You can create a pascal triangle as an infinite, lazy, nested list
pascal :: [[Integer]]
pascal = repeat 1 : map (scanl1 (+)) pascal
, , , repeat 1 .. . , , O (n).
, , .
> pascal !! 19 !! 19
35345263800
, .
:
> putStrLn $ unlines $ take 5 $ map (unwords . map show . take 5) $ pascal
1 1 1 1 1
1 2 3 4 5
1 3 6 10 15
1 4 10 20 35
1 5 15 35 70
, memoize . , data-memocombinators:
import Data.MemoCombinators
pascal :: Integer -> Integer -> Integer
pascal = memo2 integral integral pascal'
pascal' :: Integer -> Integer -> Integer
pascal' 1 _ = 1
pascal' _ 1 = 1
pascal' x y = (pascal (x - 1) y) + (pascal x (y - 1))