1

I am struggling to figure out how concatMap relates to the =<< operator. Could someone please explain why:

f x = concatMap g $ take 5 $ x

becomes

f = (g =<<) . take 5

in point free. I can see that the types of concatMap and =<< match but I don't understand why.

matt
  • 1,376
  • 7
  • 19
  • 2
    `f = concatMap g . take 5` would also be point-free. `a >>= f` is `concatMap f a` because that’s the definition of the list monad. – Ry- Aug 24 '16 at 14:30

1 Answers1

3

The substitution of =<< for concatMap has nothing to do with point-free'ness.

>>= for lists is defined to be a combination of concat and map (which is in turn equivalent to concatMap):

xs >>= f = concat (map f xs)

and of course =<< is just >>= flipped.

An explanation of the monad instance for lists can be found at: https://en.wikibooks.org/wiki/Haskell/Understanding_monads/List

Erik Kaplun
  • 33,421
  • 12
  • 92
  • 102
  • 1
    yes, my question was asked poorly. Just reading up on what you wrote.. thanks. Reading up on what you wrote, Is it also a good way of thinking about it along the lines that `concatMap` is `join fmap` for lists (and indeed all monads) – matt Aug 24 '16 at 14:53
  • @matthias `concatMap = concat .: map = (concat .) . map` by definition, and for lists `map = fmap` and `concat = join`, so. And, in general, [`((g<=).join.(f)`](http://stackoverflow.com/questions/11234632/monads-with-join-instead-of-bind/11249714#11249714). – Will Ness Aug 24 '16 at 15:34