update code
This commit is contained in:
parent
a9c3ac93c1
commit
123b8a632e
6 changed files with 28 additions and 17 deletions
2
Lambda-Riviera-000-Intro-FP/.gitignore
vendored
Normal file
2
Lambda-Riviera-000-Intro-FP/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.hi
|
||||
*.o
|
|
@ -4,18 +4,17 @@
|
|||
--install-ghc
|
||||
-}
|
||||
|
||||
-- Pureté
|
||||
|
||||
-- | (.) evaluate from right to left
|
||||
-- so first add 1
|
||||
-- then square that value
|
||||
-- finaly multiply by 10
|
||||
f :: Int -> Int
|
||||
f = (*10) . (^2) . (+1)
|
||||
-- Pureté 01
|
||||
import Foreign (f)
|
||||
-- on ne sait pas trop ce que fait f
|
||||
-- mais on connait son type
|
||||
-- f :: Int -> Int
|
||||
-- f est déclaré comme ne faisant aucun effet de bord.
|
||||
|
||||
main :: IO ()
|
||||
main = print (sum list)
|
||||
where
|
||||
-- @map@ applique une fonction à tous les éléments d'une liste
|
||||
-- map :: (a -> b) -> [a] -> [b]
|
||||
list :: [Int]
|
||||
list = map f [1..100000]
|
||||
|
|
BIN
Lambda-Riviera-000-Intro-FP/005_purete_par
Executable file
BIN
Lambda-Riviera-000-Intro-FP/005_purete_par
Executable file
Binary file not shown.
|
@ -5,21 +5,18 @@
|
|||
--package parallel
|
||||
-}
|
||||
|
||||
-- Pureté
|
||||
|
||||
-- Pureté 02
|
||||
import Foreign (f)
|
||||
-- on ne sait pas trop ce que fait f
|
||||
-- mais on connait son type
|
||||
-- f :: Int -> Int
|
||||
-- f est déclaré comme ne faisant aucun effet de bord.
|
||||
import Control.Parallel.Strategies (parMap,parList,rseq)
|
||||
|
||||
-- | Same as @map@ but use all core in parallel
|
||||
pmap :: (a -> b) -> [a] -> [b]
|
||||
pmap = parMap rseq
|
||||
|
||||
-- | (.) evaluate from right to left
|
||||
-- so first add 1
|
||||
-- then square that value
|
||||
-- finaly multiply by 10
|
||||
f :: Int -> Int
|
||||
f = (*10) . (^2) . (+1)
|
||||
|
||||
main :: IO ()
|
||||
main = print (sum list)
|
||||
where
|
||||
|
|
10
Lambda-Riviera-000-Intro-FP/Foreign.hs
Normal file
10
Lambda-Riviera-000-Intro-FP/Foreign.hs
Normal file
|
@ -0,0 +1,10 @@
|
|||
module Foreign
|
||||
(f)
|
||||
where
|
||||
|
||||
-- | (.) evaluate from right to left
|
||||
-- so first add 1
|
||||
-- then square that value
|
||||
-- finaly multiply by 10
|
||||
f :: Int -> Int
|
||||
f = (*10) . (^2) . (+1)
|
3
Lambda-Riviera-000-Intro-FP/compile-purete.sh
Executable file
3
Lambda-Riviera-000-Intro-FP/compile-purete.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
stack ghc --package parallel -- -threaded -O2 005_purete_par.hs
|
Loading…
Reference in a new issue