Created
June 8, 2011 12:59
-
-
Save wridgers/1014370 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fact :: (Integral a) => a -> a | |
fact f | |
| f == 0 = 1 | |
| otherwise = f*fact (f-1) | |
fac :: (Integral a) => a -> a | |
fac 0 = 1 | |
fac n = n*fac(n-1) |
I thought that you were trying to create a tailrecursive variant. Like this:
fac :: (Integral a) => a -> a
fac n = tailFac n 1
where tailFac 0 p = p
tailFac n p = tailFac (n-1) (n*p)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was just experimenting with guards. :) I realise why it didn't work now, stupid typo. fact f_(f-1) should be f_fact (f-1). Whoops! Cheers though. :)