Factor and Haskell comparison
Submitted by metaperl on Thu, 02/01/2007 - 11:23am.
::
Haskell
let sq = (\x -> x * x) in map sq $ map sq [1 .. 3]
Factor
{ 1 2 3 } [ sq ] map [ sq ] map .
Haskell 2
let sq = (\x -> x*x) in map (sq . sq) [1..3]
Factor 2
{ 1 2 3 } [ sq sq ] map .
Factor 3
3 [ 1+ sq sq ] map .
CONCLUSION
One interesting thing is that no new language mechanisms were necessary in Factor. In Haskell, one had to know $ and the composition operator . as well a varioius precedence rules to make clean concise code.
- metaperl's blog
- Login to post comments
map (sq . sq) [1..10] where sq x = x * xHuh? (.) and ($) are part of the language spec of Haskell. They're just ordinary functions in the Prelude.
I'd probably write it as: