[Haskell-beginners] factorial question
Nick Vanderweit
nick.vanderweit at gmail.com
Fri Aug 31 18:52:45 CEST 2012
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
<kmandpjlynch at verizon.net>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.
More information about the Beginners
mailing list