Last active
December 22, 2015 06:18
-
-
Save seanparsons/6429556 to your computer and use it in GitHub Desktop.
Possibly parallel and memoised fibonacci.
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
import Control.Parallel | |
nfib :: Int -> Int | |
nfib = (map fib [0 ..] !!) | |
where fib 0 = 0 | |
fib 1 = 1 | |
fib n = par n1 (pseq n2 (n1 + n2)) | |
where n2 = nfib (n-2) | |
n1 = nfib (n-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment