[Haskell-cafe] lawless instances of Functor
Ryan Ingram
ryani.spam at gmail.com
Tue Jan 5 12:59:34 EST 2010
On Mon, Jan 4, 2010 at 3:01 PM, Derek Elkins <derek.a.elkins at gmail.com> wrote:
> So without doing funky stuff involving bottoms and/or seq, I believe
> that fmap id = id implies the other functor law (in this case, not in
> the case of the general categorical notion of functor.)
So lets play with bottoms and/or seq.
> data X a = X a
> instance Functor X where
> fmap f x = f `seq` case x of X a -> f a
fmap id x
= id `seq` case x of X a -> X (id a)
= case x of X a -> X a
= id x
fmap (const () . undefined) x
= fmap (\a -> const () (undefined a)) x
= fmap (\a -> ()) x
= case x of X a -> X ()
(fmap (const ()) . fmap undefined) x
= fmap (const ()) (fmap undefined x)
= const () `seq` case (fmap undefined x) of X a -> X ()
= case (fmap undefined x) of X a -> X ())
= case (undefined `seq` case x of X a -> X (undefined a)) of X a -> X ()
= case undefined of X a -> X ()
= undefined
More information about the Haskell-Cafe
mailing list