[Haskell] Creating a factorial function in GHC
lemming at henning-thielemann.de
Wed May 9 10:35:43 CEST 2012
On Wed, 9 May 2012, Angus Comber wrote:
> I am trying to create a factorial function in GHC. I am following the
> online learnyouahaskell.com book (specifically types-and-typeclasses
> Bear in mind this is my day 1 of learning Haskell.
Then beginners at haskell.org might be a better place to ask, since
haskell at haskell.org is for announcements.
> The book suggests:
> factorial :: Integer -> Integer
> factorial n = product [1..n]
> But if I enter first line then press <Enter> I see:
> <interactive>:1:1 Not in scope: 'factorial'
> What am I doing wrong?
The code you entered is intended to be the content of a text file that can
be loaded into GHCi or Hugs. If you want to write it immediately into GHCi
you may write:
Prelude> let factorial :: Integer -> Integer; factorial n = product [1..n]
More information about the Haskell