Quick actions

cmd+k|ctrl+k

Navigation

Languages

Lazy Fibonacci and Factorial

Snippet info

Language

Haskell

Visibility

public

Author

homam

Created

2015-07-27T12:59:18Z

Updated

2015-10-09T18:06:28Z

import Control.Monad
import Data.List (intercalate)

facs :: [Integer]
facs = 1 : 1 : 2 : 6 : zipWith (*) [4 ..] (drop 2 . tail $ facs)

fibs :: [Integer]
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

main = do 
    print'' facs "fac" 90
    putStrLn $ replicate 80 '-'
    print'' fibs "fib" 110
    where
        print' f (a, b) = putStrLn $ intercalate " " [f, (show a), (show b)]
        print'' f name n = 
            sequence_ . take n . map (print' name) . zipWith (,) [0 ..] $ f 
INFO