FAQ Database Discussion Community


How to make Monoid instance for my type?

haskell,monoids
I have the following type: data SomeType = Var String deriving (Eq,Show) newtype TypeA = TypeA [(String, SomeType)] deriving (Eq,Show) Also, I have a function: fun1 :: TypeA -> TypeA -> TypeA I can use this function for mappend. I don't understand, how to implement Monoid interface in my case....

Arrow to add one element at a time

xml,haskell,arrows,hxt,monoids
This question is about HXT, but I guess it's applicable to conception of ArrowPlus in general. Consider the following program: module Main (main) where import Text.XML.HXT.Core import Control.Monad (void) main :: IO () main = void $ runX $ root [] [foo] >>> writeDocument [withIndent yes] "test.xml" foo :: ArrowXml...

How can I express foldr in terms of foldMap for type-aligned sequences?

haskell,types,monoids,type-variables,foldable
I'm playing around with type-aligned sequences, and in particular I'm messing around with the idea of folding them. A foldable type-aligned sequence looks something like this: class FoldableTA fm where foldMapTA :: Category h => (forall b c . a b c -> h b c) -> fm a b...

Scalaz `Tag.apply`: How does it work?

scala,scalaz,monoids
Hi I am studying the Advanced Scala book, and I have some trouble understading this piece of code from scalaz source: object Tag { /** `subst` specialized to `Id`. * * @todo According to Miles, @specialized doesn't help here. Maybe manually specialize. */ @inline def apply[@specialized A, T](a: A): A...

Why is there not 'Alternative' instance for 'Control.Applicative.Const'

haskell,applicative,monoids
There is an instance Monoid a => Monoid (Const a b) for the Const functor from Control.Applicative. There is also an instance Monoid m => Applicative (Const m). I would therefore expect that there is also an instance Monoid m => Alternative (Const m) that coincides with the one for...

Why does the Alternative typeclass need to be a sub-class of Control.Applicative

haskell,applicative,monoids
Haskell provides a standard typeclass 'Alternative' that effectively provides the <|> operator for any type that is also an Applicative. As I understand it Alternative is considered a Monoid on Applicative's, however the <|> operator seems to make complete sense in a lot of types that aren't Applicative Functors as...