
Good afternoon, I'm going thru Graham Hutton's book "Programming in Haskell" [and am viewing the associated online lectures by Erik Meijer and Graham]. I find both to be excellent. My problem is with the following statements: factorial' :: Int -> Int factorial' 0 = 1 factorial' (n+1) = (n+1)*factorial' n When I load this into GHC I get the following error: pihch01.hs:128:13: Parse error in pattern: n + 1 I'd appreciate any advice. Good day

On Fri, Aug 31, 2012 at 12:23 PM, KMandPJLynch
*factorial' :: Int -> Int* *factorial' 0 = 1* *factorial' (n+1) = (n+1)*factorial' n*
n+k patterns were removed from Haskell 2010. You can re-enable them in GHC with {-# LANGUAGE NPlusKPatterns #-} or {-# LANGUAGE Haskell98 #-} as the first line of the source file. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms

You probably don't want to use n+k patterns. Here is a clearer way to write it: factorial' :: Int -> Int factorial' 0 = 1 factorial' n = n*factorial' (n-1) Nick On Friday, August 31, 2012 12:30:34 PM Brandon Allbery wrote:
On Fri, Aug 31, 2012 at 12:23 PM, KMandPJLynch
wrote: *factorial' :: Int -> Int* *factorial' 0 = 1* *factorial' (n+1) = (n+1)*factorial' n*
n+k patterns were removed from Haskell 2010. You can re-enable them in GHC with
{-# LANGUAGE NPlusKPatterns #-}
or
{-# LANGUAGE Haskell98 #-}
as the first line of the source file.
participants (3)
-
Brandon Allbery
-
KMandPJLynch
-
Nick Vanderweit