[Haskell-beginners] Functor instance

sasa bogicevic brutallesale at gmail.com
Mon Jan 9 16:26:12 UTC 2017

Good explanation! Thanks I understand it now

Sasa Bogicevic
    phone: +381606006200

> On Jan 9, 2017, at 17:00, Francesco Ariis <fa-ml at ariis.it> wrote:
>> On Mon, Jan 09, 2017 at 04:41:39PM +0100, sasa bogicevic wrote:
>> Hi all,
>> Can someone explain to me why exactly when defining the Functor
>> instance for type that has polimorphic parameter constraint I
>> am not allowed to put that parameter in definition. So basically:
>> data Four a b c d = Four a b c d
>> instance Functor (Four a b c) where  <-- why can't I specify also
>> param d here ??
>>    fmap f (Four a b c d) = Four a b c (f d)
> Hello Sasa,
>    think for a moment about functors you already know: Maybe a, [a],
> (Either e) a, etc. In every case there is an `a` and something preceding
> a (we can call it `f`).
> Now let's look at the class-definition of functor.
>    class Functor f where -- etc. etc.
> Here you have it, `f`; so for the instance you should only place
> the `f`-part in there, like
>    instance Functor Maybe where        -- not Maybe a!
>    instance Functor (Four a b c) where -- without the a too!
> It makes sense as `f` will stay the same and `a` will be mapped over
> (and change).
> Indeed you can very this with ghci (using :k Functor, :k Maybe etc.),
> but after a while it sinks in.
> Does this help?
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

More information about the Beginners mailing list