Re: [Haskell-cafe] Questions about the Functor class and it's use in "Data types à la carte"

David Menendez dave at zednenem.com
Fri Dec 14 21:00:15 EST 2007


On Dec 14, 2007 4:18 PM, Felipe Lessa <felipe.lessa at gmail.com> wrote:

>
> If it is not, the implementation "fmap f = id" is really the only one
> sound,
> right?
>

It pretty clear what you meant here, but it's worth noting that "fmap f =
id" is a type error.

Consider:

    id :: a -> a
    (\Val i -> Val i) :: Val a -> Val b

These can (and, if Val is a newtype, will) be compiled to the same code, but
they don't have the same type. In particular, there is no way to unify "a ->
a" with "f a -> f b" for any f.

And yes, I'm pretty sure that's the only possible implementation for that
type which satisfies the functor laws.

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071214/4dd0c101/attachment.htm


More information about the Haskell-Cafe mailing list