I am using ghci compiler with version 7.8.3 on windows 7. I am getting error message showing parse error on input `->'. I have the following code for lambda expression in haskell.
Note that =\ is an operator. Since you want to assign a lambda expression to the name add, you need a space: = \ .
– Code-Apprentice
2 Answers
5
votes
When defining a function interactively in ghci, you have to bind it using a let like this:
let add = \x y -> x + y
2
votes
I just wrote:
add = \x y -> x + y
main = do
print $ add 1 2
and it compiled and output 3.
Unless your intent is to practice unsugared code though, I would write it out as:
add x y = x + y
Or
add = (+)
which is "point-free" form.
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more
=\
is an operator. Since you want to assign a lambda expression to the nameadd
, you need a space:= \
. – Code-Apprentice