
3 Dec
2007
3 Dec
'07
6:45 p.m.
On Dec 3, 2007 9:23 PM,
2. If it's logically a Functor, strictness will break the axioms, so don't do that.
What do you mean by breaking the axioms? If I define
data List a = Nil | Cons !a !(List a)
instance Functor List where fmap f Nil = Nil fmap f (Cons x xs) = Cons (f x) (fmap f xs)
Then the laws 1) fmap id == id 2) fmap f . fmap g == fmap (f . g) won't hold? What am I missing here? Are there some bottoms hiding out? ... Oh, I think I saw one! Let
f x = 1 g x = _|_ l = Cons 2 Nil
Then
fmap f (fmap g l) == fmap f (Cons _|_ Nil) == fmap f _|_ == _|_
but
fmap (f . g) l == Cons (f (g 2)) Nil == Cons (f _|_) Nil == Cons 1 Nil
right? Very interesting. Is this written somewhere on the wiki? Cheers, -- Felipe.