- Joined
- Sep 18, 2016
Still interested in Lisp but I managed to make some little functions in Haskell. Haskell has always fascinated me for being a difficult language. Only the really smart people write Haskell. I had fun with it.
Code:
-- tail factorial function in haskell
tfac :: Integer -> Integer -> Integer
tfac x y = if x < 2 then y else tfac (x - 1) (x * y)
collatz :: Integer -> Integer -> Integer
collatz c d
| c == 1 = d
| odd c = collatz ((3 * c) + 1) (d + 1)
| not (odd c) = collatz (c `div` 2) (d + 1)
main :: IO()
--main = tfac 6 1
main = do
let a = tfac 6 1
-- let answer = show a
--putStrLn answer
putStrLn (show a)
let b = collatz 13 1
putStrLn (show b)