Difference between revisions of "Talk:Compose"

From HaskellWiki
Jump to navigation Jump to search
m
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 
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/>
 
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/>
<code>
+
<haskell>
 
composeArrow :: [a -> a] -> a -> a <br/>
 
composeArrow :: [a -> a] -> a -> a <br/>
 
composeArrow = foldr ((>>>) . arr) (arr id)
 
composeArrow = foldr ((>>>) . arr) (arr id)
</code>
+
</haskell>
   
 
<br>Or maybe this:<br>
 
<br>Or maybe this:<br>
<code>
+
<haskell>
 
composeArrow :: [a -> a] -> a -> a
 
composeArrow :: [a -> a] -> a -> a
 
composeArrow = foldl ((>>>) . arr) returnA
 
composeArrow = foldl ((>>>) . arr) returnA
</code>
+
</haskell>
  +
  +
----
  +
  +
The first version does not need the function composition, because the functions could be applied immediately.
  +
This leads to
  +
  +
<haskell>
  +
compose = flip (foldl (flip id))
  +
</haskell>
  +
Shall I replace the first solution?
  +
  +
----
  +
I would write:
  +
<haskell>
  +
compose = foldr (flip (.)) id
  +
</haskell>

Latest revision as of 10:12, 9 February 2007

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.

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