I cannot reproduce the error you claim you get. If you are writing that code into a file and compiling it with ghc
the error is:
<filename>.hs:2:38: parse error on input ‘=’
And the problem is that the syntax for where
is wrong. Either write:
an_expression where z = x+y
Or you have to use curly braces:
an_expression where {z=x+y;}
You cannot use parenthesis to group an assignment.
Note that when writing in ghci you must group together the declarations and use a let
to define functions:
Prelude> let {addConcat :: [Int] -> [Int]; addConcat [x,y] = [z,z+y] where z=x+y;}
Prelude> addConcat [1,2]
[3,5]
Note also that even fixing this your function still has a type error because the second argument of :
must be a list while z+y
is a number. You want z:[z+y]
or more simply [z, z+y]
.