jacob614

haskell

Oct 7th, 2013
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. factorial :: Int -> Int
  2. factorial num
  3.     | num == 0   = 1
  4.     | otherwise  = num * factorial (num-1)
  5.  
  6. -- this is deferred operation or something, answer not evaluated until the recursion starts unwinding?:
  7. factorial2 :: Int -> Int
  8. factorial2 n = help n 1
  9. help :: Int -> Int -> Int
  10. help n m
  11.     | n == 0    = m
  12.     | otherwise = help (n - 1) (m * n)
Advertisement
Add Comment
Please, Sign In to add comment