I have 2 dummy functions. In function 2, I'm trying to set a parameter to a different value. In function 1, I copy the parameter value to a variable and then try to change the value of that variable.
In both case, I get the same error (Shown below). I may not understand what is the cause of the error, but it seems that I can't modify the value of a variable once set. If that's the case, why? And if it is for a different reason, what is it?
Function1
myFunction :: [Char] ->[Char] -> [Char]
myFunction a b = if length a > 1
then do
let a1 = a
a = a1 ++ "333"
else
b
Function2
myFunction :: [Char] ->[Char] -> [Char]
myFunction a b = if length a > 1 then a = "333" else b
Error
Stackoverflow.hs:8:28: error:
parse error on input `='
Perhaps you need a 'let' in a 'do' block?
e.g. 'let x = 5' instead of 'x = 5'
|
8 | a = a1 ++ "333"
| ^
Common main used for both function:
main :: IO ()
main = do
putStrLn (myFunction "stack" "overflow")