As people have pointed out in the comments, a definition on a single line in GHCi 8 replaces any previous definition. If you want to enter a multi-pattern definition, you need to use the special :{
and :}
codes to start and end a multi-line command. So, the following works fine:
Prelude> :{
Prelude| fact 0 = 1
Prelude| fact n = n * fact (n-1)
Prelude| :}
Prelude> fact 10
3628800
Prelude>
(Note that this is applicable to GHCi 8 only, not 7.)
Also, mind the order in your definition. In Haskell, order of patterns matters, so if you try to match fact n
first, it will always match, so your fact 0
pattern will never be used..
Edit: For GHCI 7, you need to use the let
syntax with appropriate indentation to enter a multi-pattern definition:
Prelude> :{
Prelude| let fact 0 = 1
Prelude| fact n = n * fact (n-1)
Prelude| :}
Prelude> fact 10
3628800
Prelude>