Search code examples
haskellcurryingparse-error

(Haskell) Parse error in pattern after Currying


I am getting a parse error after I changed this:

h :: ([Int],Int,[Int])->[[Int]]

h ([],k,x) =[[]]

h(y:[],k,x) = [x++k:[y]]

h(y:xs,k,x)= [x++k:y:xs]++h(xs,k,x++[y])

to this: at line 3

h :: [Int]->Int->[Int]->[[Int]]

h [] k x  =[[]]

h (y:[]) k x = [x++k:[y]]

h y:xs k x = [x++k:y:xs]++h(xs,k,x++[y])

Solution

  • There are two problems with this line:

    h y:xs k x = [x++k:y:xs]++h(xs,k,x++[y])
      ^^^^                    ^^^^^^^^^^^^^
      (1)                     (2)
    
    1. You need parens around this pattern - (y:xs)
    2. Unlike in other languages like C, Java, C#, etc, in Haskell you don't use commas to separate parameters to functions.