[Haskell-cafe] Possible Improvements
Felipe Lessa
felipe.lessa at gmail.com
Mon Dec 3 18:45:10 EST 2007
On Dec 3, 2007 9:23 PM, <ajb at spamcop.net> wrote:
> 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.
More information about the Haskell-Cafe
mailing list