[Haskell-cafe] How to understand the fmap here ?

minh thu noteed at gmail.com
Tue May 5 05:35:48 EDT 2009


2009/5/5 z_axis <z_axis at 163.com>:
> The following code snippets is from xmonad:
> -- Given a window, find the screen it is located on, and compute
> -- the geometry of that window wrt. that screen.
> floatLocation :: Window -> X (ScreenId, W.RationalRect)
> --.......
> rr <- snd `fmap` floatLocation w
>
> Prelude> :i fmap
> class Functor f where fmap :: (a -> b) -> f a -> f b
>
> It seems it is different from the definition of fmap ?
> sincerely!

X is a Functor (and a Monad).

floatLocation w :: X (ScreenId, W.RationalRect) -- i.e. f is X and a
is (ScreenId, W.RationalRect)
snd :: (ScreenId, W.RationalRect) -> W.RationalRect
fmap :: (same as snd) -> X (ScreenId, W.RationalRect) -> X W.RationalRect

Makes sense ?

Cheers,
Thu


More information about the Haskell-Cafe mailing list