Last active
April 23, 2019 13:33
-
-
Save chrisdone/5d41f7c77cdeb978cc782297a0fbf03f to your computer and use it in GitHub Desktop.
Fibs in Prana
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fib :: Int -> Int | |
fib n = go 0 1 0 | |
where | |
go !acc0 !acc1 !i | |
| i == n = acc0 | |
| otherwise = go acc1 (acc0 + acc1) (i + 1) | |
it :: Int | |
it = fib 50 | |
{- | |
Output: | |
main:Fib.it = | |
(ghc-prim:GHC.Types.I# (IntLit 12586269025)) | |
581.80 us | |
-} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fibs = 1 : 1 : zipWith (+) fibs (tail fibs) | |
taker :: Int -> [Int] -> [Int] | |
taker count xs = go 0 xs | |
where go cur xs | cur == count = [] | |
go cur [] = [] | |
go cur (x:xs) = x : go (cur+1) xs | |
it :: [Int] | |
it = taker 10 fibs | |
{- | |
Output: | |
main:Fib.it = | |
(ghc-prim:GHC.Types.: (ghc-prim:GHC.Types.I# (IntLit 1)) (ghc-prim:GHC.Types.: (ghc-prim:GHC.Types.I# (IntLit 1)) (ghc-prim:GHC.Types.: (ghc-prim:GHC.Types.I# (IntLit 2)) (ghc-prim:GHC.Types.: (ghc-prim:GHC.Types.I# (IntLit 3)) (ghc-prim:GHC.Types.: (ghc-prim:GHC.Types.I# (IntLit 5)) (ghc-prim:GHC.Types.: (ghc-prim:GHC.Types.I# (IntLit 8)) (ghc-prim:GHC.Types.: (ghc-prim:GHC.Types.I# (IntLit 13)) (ghc-prim:GHC.Types.: (ghc-prim:GHC.Types.I# (IntLit 21)) (ghc-prim:GHC.Types.: (ghc-prim:GHC.Types.I# (IntLit 34)) (ghc-prim:GHC.Types.: (ghc-prim:GHC.Types.I# (IntLit 55)) (ghc-prim:GHC.Types.[]))))))))))) | |
28.68 us | |
Case Allocated GCs Max | |
Eval 886,680 0 0 | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment