Wednesday 5 October 2011

Haskell - parse error in pattern: n + 1

Should you get the following error from Haskell
Parse error in pattern: n + 1
this maybe because you are using the n+1 pattern, which is no longer included by default eg
> power :: Double -> Int -> Double
> power x 0         = 1
> power x (n + 1)   = x * power x n
the fix is to include
> {-# LANGUAGE NPlusKPatterns #-}
Hope this helps.

No comments:

Post a Comment