1
votes

I'm pretty new in Haskell and I have got a very strange mistake:

insertion el [] = [el]
insertion el (x:xs) = | el < x = el:x:xs
                      | otherwise = x:insertion el xs

Which gives me this error, on the second line at the caractere just after the pipe: parse error on input `|' Failed, modules loaded: none.

I don't really get it, would you have a tips ? Thanks in advance :)

1
remove the '=' before the first '|' - Ingo
Thank you very much ! There was the '=' in the tutorial I read so I could not imagin that would be the problem. Thanks again :) - user2145240
What tutorial? Maybe it can be fixed without too much hassle. - Daniel Fischer

1 Answers

5
votes

When you use guards (the pipe symbol) with function definitions, you do not follow the function name and paramaters with an equal sign. It should be written like this:

insertion el [] = [el]
insertion el (x:xs)
   | el < x    = el:x:xs
   | otherwise = x:insertion el xs

The first guard doesn't need to be on the next line, but that tends to be the general style.