[Haskell-cafe] lawless instances of Functor

Steffen Schuldenzucker sschuldenzucker at uni-bonn.de
Tue Jan 5 16:15:40 EST 2010


Brent Yorgey wrote:
> On Mon, Jan 04, 2010 at 11:49:33PM +0100, Steffen Schuldenzucker wrote:
>> [...]
> 
> As others have pointed out, this doesn't typecheck; but what it DOES
> show is that if we had a type class
> 
>   class Endofunctor a where
>     efmap :: (a -> a) -> f a -> f a
> 
> then it would be possible to write an instance for which efmap id = id
> but efmap (f . g) /= efmap f . efmap g.  The difference is that with
> the normal Functor class, once you have applied your function f :: a
> -> b to get a b, you can't do anything else with it, since you don't
> know what b is.  With the Endofunctor class, once you have applied f
> :: a -> a, you CAN do something with the result: namely, apply f
> again.  

Oops. Yeah, sorry, it's been ... late and stuff...

Steffen



More information about the Haskell-Cafe mailing list