
On Wednesday 02 March 2011 15:03:00, Patrick Lynch wrote:
In Learn You a Haskell for Great Good!, the author Miran Lipovaca indicates that to understand Monads you need to know Functors... So, I noticed the following:
class Functor f where fmap::(a->b)->f a->f b
instance Functor [] where fmap = map
map::(a->b)->[a]->[b]
if [] is substituted for f in the class definition of Functor the following is obtained class Functor [] where fmap::(a->b)->[]a->[]b
my questions are: 1. is this substitution ok? 2. is []a = [a]? 3. is []b = [b]?
if 2. and 3. are valid then the following is obtained: fmap::(a->b)->[a]->[b] which is the same as map type and therefore: fmap = map. QED.
Can you please answer questions 2 and 3 above?
Thank you
Yes, that's correct. The list constructor is special ([] isn't valid Haskell for a type constructor, so it's wired in), it can be used prefix ([] a) or `roundfix' ([a]). Ordinarily, you can use type constructors prefix or infix (if they take two type arguments), e.g. a -> b = (->) a b; Either a b = a `Either` b.