update
Former-commit-id: bdede6ed1b6f578f2ef046c338caf02d0b29d453 [formerly 7187de361b53e9c8ec121df379b762f2db736ea2] Former-commit-id: 447d58460fbbfd05ffe08428a1288e392637561d
This commit is contained in:
20
_embed/public/ace/demo/kitchen-sink/docs/haskell.hs
Normal file
20
_embed/public/ace/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)
|
||||
Reference in New Issue
Block a user