-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathparmonad.hs
More file actions
27 lines (25 loc) · 747 Bytes
/
parmonad.hs
File metadata and controls
27 lines (25 loc) · 747 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import Control.Exception
import System.Environment
import Control.Monad.Par.Scheds.Trace
-- NB. using Trace here, Direct is too strict and forces the fibs in
-- the parent; see https://github.com/simonmar/monad-par/issues/27
-- <<fib
fib :: Integer -> Integer
fib 0 = 1
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
-- >>
main = do
args <- getArgs
let [n,m] = map read args
print $
-- <<runPar
runPar $ do
i <- new -- <1>
j <- new -- <1>
fork (put i (fib n)) -- <2>
fork (put j (fib m)) -- <2>
a <- get i -- <3>
b <- get j -- <3>
return (a+b) -- <4>
-- >>