Who likes to tell me what is wrong with this code (syntactically)?
-- merge two sorted lists
mergeX [] b res = b ++ res
mergeX a [] res = a ++ res
mergeX a:as b:bs res
| a > b = mergeX as b:bs a:res
| otherwise = mergeX a:as bs b:res
Interpreter:
Parse error in pattern: mergeX
You need some parenthesis:
mergeX [] b res = b ++ res
mergeX a [] res = a ++ res
mergeX (a:as) (b:bs) res
| a > b = mergeX as (b:bs) (a:res)
| otherwise = mergeX (a:as) bs (b:res)
The reason is because :
has a lower precedence than function application, so mergeX a:as b:bs res
will be parsed as:
(mergeX a):(as b):(bs res)
which is an error.