i have one Haskell function, which i don't understand but want to.
i :: Int
i = ((\g x -> g x + g x) (\y -> y)) 3
I know what a lambda function is: a nameless function.
E.g. (\x -> x) 3 takes 3 and returns it, (\x y -> x+y) 3 4 takes 3, 4 and returns 7.
But in this special case i can't interpret it. I hope you can help me.
Btw. the solution for this function is 6.
Now your (\y -> y) function is equivalent to id. Let's rewrite your function using that:
i = ((\g x -> g x + g x) id) 3
Now apply the id function to (\g x -> g x + g x). This will get reduced to:
i = (\x -> id x + id x) 3
Now it's simple:
i = id 3 + id 3
i = 6
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