[Haskell-cafe] Function composition questions from a newbie
atheist.diehard at yahoo.com
Tue Dec 1 03:12:18 EST 2009
I am a newbie. Consider this code:
square x = x * x
add3 x y z = x + y + z
> what about (square . add3) 1 2?
> It doesn't work since add3, when curried (arguments of square "blended"
> with add3's) with 1 argument becomes:
> add3 :: Num a => a -> a -> a
> which is a function that accepts 2 arguments and it's not compatible with
> square's a.
Thank you so much for your clarification. To understand better, I tried some
1) composition = (square . add3) 5 -- illegal as you had explained
2) composition x = (square . add3) 1 2 3 -- legal, but why? what is the
significance of x
3) composition x = (square . add3) x -- legal, but why?
4) composition x y = (square . add3) x y -- legal, but why?
5) composition x = (square . add3) x 3 -- legal, but why?
I dont understand why the above functions are legal, and what arguments they
need. Could you please give an example of how to invoke it?
View this message in context: http://old.nabble.com/Function-composition-questions-from-a-newbie-tp26570201p26587250.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
More information about the Haskell-Cafe