add demo docs
This commit is contained in:
parent
5d63adb2a7
commit
73f299d3f0
12 changed files with 243 additions and 9 deletions
20
demo/kitchen-sink/docs/haskell.hs
Normal file
20
demo/kitchen-sink/docs/haskell.hs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
-- Type annotation (optional)
|
||||
fib :: Int -> Integer
|
||||
|
||||
-- With self-referencing data
|
||||
fib n = fibs !! n
|
||||
where fibs = 0 : scanl (+) 1 fibs
|
||||
-- 0,1,1,2,3,5,...
|
||||
|
||||
-- Same, coded directly
|
||||
fib n = fibs !! n
|
||||
where fibs = 0 : 1 : next fibs
|
||||
next (a : t@(b:_)) = (a+b) : next t
|
||||
|
||||
-- Similar idea, using zipWith
|
||||
fib n = fibs !! n
|
||||
where fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
|
||||
|
||||
-- Using a generator function
|
||||
fib n = fibs (0,1) !! n
|
||||
where fibs (a,b) = a : fibs (b,a+b)
|
||||
Loading…
Add table
Add a link
Reference in a new issue