[Haskell-cafe] Functor instance for FunPB

Daniel Díaz Casanueva dhelta.diaz at gmail.com
Sat May 6 19:37:24 UTC 2017


Hallo.

You can try reusing fmap.

>>>

data FunPB a b = FunPB { runFunPB :: a -> (a,[b])

fmap f (FunPB g) = FunPB $ fmap (fmap (fmap f)) g

>>>

This works because (a->), (a,), and [] are all functors.

Freundliche Grüße,
Daniel.

On Sat, May 6, 2017 at 9:04 PM, MarLinn <monkleyon at gmail.com> wrote:

>
> On 2017-05-06 20:38, David Kraeutmann wrote:
>
>> The only lawful instance I can think of is:
>> instance Functor (FunPB a) where
>>    fmap f (FunPB g) = FunPB $ \k -> let (a,b) = g k in (a, fmap f b)
>>
>> which is fairly straightforward IMO.
>>
> And because it's closer to the original style:
>
>         fmap f = FunPB .((.)((<$>).(<$>)$f)). runFunPB
>
> Now it's STARRING INTO YOU SOUL. And it's also so much easier to read.
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170506/01b8e1e5/attachment.html>


More information about the Haskell-Cafe mailing list