From HaskellWiki
Revision as of 10:12, 9 February 2007 by JeanPhilippeBernardy (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Reading this page got me to write an arrow version of compose. Don't know if it should be included or not since it isn't a monadic solution.<p/>

composeArrow :: [a -> a] -> a -> a <br/>
composeArrow = foldr ((>>>) . arr) (arr id)

Or maybe this:

composeArrow :: [a -> a] -> a -> a
composeArrow = foldl ((>>>) . arr) returnA

The first version does not need the function composition, because the functions could be applied immediately. This leads to

compose = flip (foldl (flip id))

Shall I replace the first solution?

I would write:

compose = foldr (flip (.)) id