Created
January 5, 2018 08:47
-
-
Save jarekratajski/8b28fa61bde683e4bfd6352c9068a6ec to your computer and use it in GitHub Desktop.
This file contains 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
fibbtcoinner 0 sum presum = sum | |
fibbtcoinner n sum presum = fibbtcoinner (n-1) (sum + presum) sum | |
fibbtco n = fibbtcoinner n 1 0 | |
fibbnaive 0 = 1 | |
fibbnaive 1 = 1 | |
fibbnaive n = fibbnaive ( n-1) + fibbnaive ( n - 2) | |
main = do | |
putStrLn $ show $ fibbtco <$> arr | |
putStrLn $ show $ fibbnaive <$> arr | |
where | |
arr = [0..10] | |
{- eta with -O0, -O1, -O2 produces | |
[1,1,2,4,8,16,32,64,128,256,512] | |
[1,1,2,3,5,8,13,21,34,55,89] | |
-} | |
{- GHC 7.10.3 with -O2 produces | |
[1,1,2,3,5,8,13,21,34,55,89] | |
[1,1,2,3,5,8,13,21,34,55,89] | |
-} | |
{- interesting eta with -O0 (only!) and BangPatterns | |
fibbtcoinner 0 sum presum = sum | |
fibbtcoinner n !sum !presum = fibbtcoinner (n-1) (sum + presum) sum | |
produces correct result | |
-} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment