[reactive] To fmap fmap or not?

Eyal Lotem eyal.lotem at gmail.com
Tue Nov 18 19:00:06 EST 2008

I see fmap as a "penetration" of one box.
fmap.fmap as a "penetration" of two boxes, and so on.

So, if you have (UI -> Behavior (Blah, a)), then the value "a" is "buried"
inside a (UI->) box, then inside a Behavior box, and then inside a (Blah,)
To change the value of "a" you can thus use:  (fmap.fmap.fmap) aToB

To access (Blah, a), instead, just use (fmap.fmap) and penetrate just 2
boxes instead of 3.

Additionally, this "trick" also works nicely with liftA2.  If you have two
values that are buried inside the same 2 boxes (For example,  two values of
type: UI -> Behavior a -- the boxes here are a (UI->) reader, and a
Behavior), then you can apply f to the "a" inside both via:

(liftA2.liftA2) f doublyBoxedA doublyBoxedB

And as usual, (liftA2.liftA2.liftA2) when the values are wrapped in 3 boxes,
and so on.


2008/11/19 Peter Verswyvelen <bugfact at gmail.com>

> Many of the fmap fmaps I've seen come from
> (fmap f) . g = (fmap f) `fmap` g = fmap (fmap f) g = (fmap (fmap f)) g =
> ((fmap.fmap) f) g = (fmap.fmap) f g
> But... to me the former is much clearer than the latter... It is less
> abstract since it uses (.) instead of fmap.
> However, I also see (fmap.fmap.fmap), so Conal must have seen a pattern
> here?
> Of course one could also write (fmap `fmap` fmap `fmap` fmap) instead of
> (fmap.fmap.fmap).
> Or as was already mentioned  with the generic replacement (.) = fmap,
> (fmap.fmap.fmap) can be written as ( (.) . (.) . (.) )
> But besides this all being very Haskelly Hackery - and maybe ASCII art that
> needs to be censured - I don't see the light yet :)
> Could somebody enlighten me?
> _______________________________________________
> Reactive mailing list
> Reactive at haskell.org
> http://www.haskell.org/mailman/listinfo/reactive
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/reactive/attachments/20081119/798cbf48/attachment.htm

More information about the Reactive mailing list