[Haskell-cafe] lawless instances of Functor
ekmett at gmail.com
Tue Jan 5 09:52:58 EST 2010
Given fmap id = id, fmap (f . g) = fmap f . fmap g follows from the free
theorem for fmap.
This was published as an aside in a paper a long time back, but I forget
On Mon, Jan 4, 2010 at 5:14 PM, Paul Brauner <paul.brauner at loria.fr> wrote:
> I'm trying to get a deep feeling of Functors (and then pointed Functors,
> Applicative Functors, etc.). To this end, I try to find lawless
> instances of Functor that satisfy one law but not the other.
> I've found one instance that satisfies fmap (f.g) = fmap f . fmap g
> but not fmap id = id:
> data Foo a = A | B
> instance Functor Foo where
> fmap f A = B
> fmap f B = B
> -- violates law 1
> fmap id A = B
> -- respects law 2
> fmap (f . g) A = (fmap f . fmap g) A = B
> fmap (f . g) B = (fmap f . fmap g) B = B
> But I can't come up with an example that satifies law 1 and not law 2.
> I'm beginning to think this isn't possible but I didn't read anything
> saying so, neither do I manage to prove it.
> I'm sure someone knows :)
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe