[Haskell-cafe] Function composition questions from a newbie

newbie2009 atheist.diehard at yahoo.com
Tue Dec 1 04:32:24 EST 2009



leledumbo wrote:
> 
> None of them are legal, at least in my WinHugs they're not. What tools are
> you using?
> 

1) I am using GHCi. I put the following into a file named composition.hs and
typed ":l composition.hs" in GHCi. I also did a ":browse Main"
2) Next, I installed WinHugs, and loaded the same hs file. It failed with an
error when processing the definition for composition2
3) is GHC the standard Haskell implementation or should i be using WinHugs?

-----------8<-----------

square x = x * x
add x y = x + y
add3 x y z = x + y + z
composition1 = add . square
-- composition1 5 6 == 31

-- composition2 = square . add -- wont work

composition2 x = (square . add) x	-- to make it work, make composition2 take
an argument
-- composition2 5 9 == 196

composition3 x y = square . (add3 x y)	-- composition3 1 2 3 == 36
composition4 x y = square . add3 x y	-- composition4 1 2 3 == 36
composition5 x y = (square . add3) x y	-- TODO: what does this mean?? how do
we invoke composition5
composition6 x = (square . add3) x 		-- TODO: what does this mean?? how do
we invoke composition5
composition7 x = (square . add3) x 8
composition8 x = (square . add3) 1 2 x
composition9 x = (square . add3) x
composition10 x = (square . add3) 1 2 3

-----------8<-----------


-- 
View this message in context: http://old.nabble.com/Function-composition-questions-from-a-newbie-tp26570201p26588106.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list