Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add strat examples

  • Loading branch information...
commit 4e0bd1072da674193dcdcdcc9a03619b2a6946e5 1 parent 300adf1
Simon Marlow authored
21  parconc-examples.cabal
@@ -49,6 +49,27 @@ executable sudoku4
49 49
 -- -----------------------------------------------------------------------------
50 50
 -- par-strat
51 51
 
  52
+executable strat
  53
+  main-is: strat.hs
  54
+  build-depends:   base >= 4.5 && < 4.7
  55
+                 , parallel ==3.2.*
  56
+  ghc-options: -threaded
  57
+  default-language: Haskell2010
  58
+
  59
+executable strat2
  60
+  main-is: strat2.hs
  61
+  build-depends:   base >= 4.5 && < 4.7
  62
+                 , parallel ==3.2.*
  63
+  ghc-options: -threaded
  64
+  default-language: Haskell2010
  65
+
  66
+executable strat3
  67
+  main-is: strat3.hs
  68
+  build-depends:   base >= 4.5 && < 4.7
  69
+                 , parallel ==3.2.*
  70
+  ghc-options: -threaded
  71
+  default-language: Haskell2010
  72
+
52 73
 executable rsa
53 74
   main-is: rsa.hs
54 75
   build-depends:   base >= 4.5 && < 4.7
2  strat.hs
... ...
@@ -1,7 +1,5 @@
1 1
 import Control.Parallel
2 2
 import Control.Parallel.Strategies (rpar, Strategy, using)
3  
-import Control.Exception
4  
-import Data.Time.Clock
5 3
 import Text.Printf
6 4
 import System.Environment
7 5
 
4  strat2.hs
... ...
@@ -1,7 +1,5 @@
1 1
 import Control.Parallel
2 2
 import Control.Parallel.Strategies (rpar, Strategy, using)
3  
-import Control.Exception
4  
-import Data.Time.Clock
5 3
 import Text.Printf
6 4
 import System.Environment
7 5
 
@@ -16,7 +14,7 @@ main = print pair
16 14
  where
17 15
   pair =
18 16
 -- <<pair
19  
-   (fib 35, fib 36) `using` evalPair rpar rpar
  17
+   (fib 35, fib 36) `using` parPair
20 18
 -- >>
21 19
 
22 20
 -- <<evalPair
32  strat3.hs
... ...
@@ -0,0 +1,32 @@
  1
+import Control.Parallel
  2
+import Control.Parallel.Strategies (rpar, rseq, Strategy, using, rparWith)
  3
+import Control.Exception
  4
+import Text.Printf
  5
+import System.Environment
  6
+
  7
+-- <<fib
  8
+fib :: Integer -> Integer
  9
+fib 0 = 1
  10
+fib 1 = 1
  11
+fib n = fib (n-1) + fib (n-2)
  12
+-- >>
  13
+
  14
+main = print pair
  15
+ where
  16
+  pair =
  17
+-- <<pair
  18
+   (fib 35, fib 36) `using` parPair rseq rseq
  19
+-- >>
  20
+
  21
+-- <<evalPair
  22
+evalPair :: Strategy a -> Strategy b -> Strategy (a,b)
  23
+evalPair sa sb (a,b) = do
  24
+  a' <- sa a
  25
+  b' <- sb b
  26
+  return (a',b')
  27
+-- >>
  28
+
  29
+-- <<parPair
  30
+parPair :: Strategy a -> Strategy b -> Strategy (a,b)
  31
+parPair sa sb = evalPair (rparWith sa) (rparWith sb)
  32
+-- >>

0 notes on commit 4e0bd10

Please sign in to comment.
Something went wrong with that request. Please try again.