[Haskell-cafe] (liftM join .) . mapM
Stephen Tetley
stephen.tetley at gmail.com
Tue Dec 29 12:24:52 EST 2009
2009/12/29 Tony Morris <tonymorris at gmail.com>:
> Can (liftM join .) . mapM be improved?
> (Monad m) => (a -> m [b]) -> [a] -> m [b]
Hi Tony
I count this as a personal preference rather than an improvement:
joinything2 :: (Monad m) => (a -> m [b]) -> [a] -> m [b]
joinything2 = liftM join `oo` mapM
oo is one of of a family of functions I use often to avoid
sectioning/composing mania. It's known to Raymond Smullyan fans as
'blackbird', though I call it oo as a pun on Standard MLs o (which is
Haskells (.) of course).
-- | Compose an arity 1 function with an arity 2 function.
-- B1 - blackbird
oo :: (c -> d) -> (a -> b -> c) -> a -> b -> d
oo f g = (f .) . g
Extending the arity works quite nicely too:
-- | Compose an arity 1 function with an arity 3 function.
-- B2 - bunting
ooo :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> e
ooo f g = ((f .) .) . g
... and so on. I've used `oooo` but some how never needed `ooooo`. Due
to their typographical appearance in infix form, the family name I
have for them is specs (i.e. glasses, googles...) - `oo`
Best wishes
Stephen
More information about the Haskell-Cafe
mailing list