[Haskell-cafe] A beginners question

Chaddaï Fouché chaddai.fouche at gmail.com
Sat Feb 23 11:45:05 EST 2008


2008/2/23, Harri Kiiskinen <harkiisk at utu.fi>:
> Dear All,
>
>  banging my head against Haskell, but liking the feeling of hurting
>  brains. Just a simple question:
>
>  If
>
>  fmap (^4) [1,2,3] >>= \i -> shows i " "
>
>  gives
>
>  "1 16 81 "

In the List Monad, (>>=) is defined as concatMap, so this code can be
translated by :
> concatMap (\i -> shows i " ") (fmap (^4) [1,2,3])

shows is applied to each elements of the list, then the strings are concatened.

Whereas in
> let xs = fmap (^4) [1,2,3] in shows xs " "
shows is applied to the whole list.

-- 
Jedaï


More information about the Haskell-Cafe mailing list