[Haskell-cafe] >>= definition for list monad in ghc

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Mon May 16 11:20:43 CEST 2011


On 16 May 2011 19:07, Michael Vanier <mvanier42 at gmail.com> wrote:
> Usually in monad tutorials, the >>= operator for the list monad is defined
> as:
>
> m >>= k = concat (map k m)  -- or concatMap k m
>
> but in the GHC sources it's defined as:
>
> m  >>=  k  =  foldr  ((++)  .  k)  []  m
>
> As far as I can tell, this definition is equivalent to the previous one
> (correct me if I'm wrong), so I was wondering why this definition was chosen
> instead of the other one.  Does anybody know?

My guess is to aid the foldr fusion RULEs...

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com



More information about the Haskell-Cafe mailing list