I don't understand composing functions with arity > 1. in ghci 7.4.1 i typed:
((*).succ) 3 4
> 16
i don't fully understand the math transformation but it's clear that it's the same as
(*) (succ 3) 4
but when i do:
( (\x y z -> x).(\a b -> a*b) ) 2 3 4 5
> 10
( (\x y z -> y).(\a b -> a*b) ) 2 3 4 5
> No instance for (Num (a0 -> t0))
and now i'm totally lost. can anyone explain what happens? ps. I know that everything in haskell has only 1 parameter but it doesn't really help me :)
Work it out this way:
(f . g) x = f (g x)
(f . g) x y = f (g x) y -- applying y
Then replace f with (*)
, g with succ
and x and y with their values:
((*) . succ) 3 4 = (*) (succ 3) 4
= (*) 4 4
= 16
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With