Skip to content

Instantly share code, notes, and snippets.

@seanparsons
Last active December 22, 2015 06:18
Show Gist options
  • Save seanparsons/6429556 to your computer and use it in GitHub Desktop.
Save seanparsons/6429556 to your computer and use it in GitHub Desktop.
Possibly parallel and memoised fibonacci.
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