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
|
--install-ghc
|
||||||
-}
|
-}
|
||||||
|
|
||||||
-- Pureté
|
-- Pureté 01
|
||||||
|
import Foreign (f)
|
||||||
-- | (.) evaluate from right to left
|
-- on ne sait pas trop ce que fait f
|
||||||
-- so first add 1
|
-- mais on connait son type
|
||||||
-- then square that value
|
-- f :: Int -> Int
|
||||||
-- finaly multiply by 10
|
-- f est déclaré comme ne faisant aucun effet de bord.
|
||||||
f :: Int -> Int
|
|
||||||
f = (*10) . (^2) . (+1)
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = print (sum list)
|
main = print (sum list)
|
||||||
where
|
where
|
||||||
|
-- @map@ applique une fonction à tous les éléments d'une liste
|
||||||
-- map :: (a -> b) -> [a] -> [b]
|
-- map :: (a -> b) -> [a] -> [b]
|
||||||
list :: [Int]
|
list :: [Int]
|
||||||
list = map f [1..100000]
|
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
|
--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)
|
import Control.Parallel.Strategies (parMap,parList,rseq)
|
||||||
|
|
||||||
-- | Same as @map@ but use all core in parallel
|
-- | Same as @map@ but use all core in parallel
|
||||||
pmap :: (a -> b) -> [a] -> [b]
|
pmap :: (a -> b) -> [a] -> [b]
|
||||||
pmap = parMap rseq
|
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 :: IO ()
|
||||||
main = print (sum list)
|
main = print (sum list)
|
||||||
where
|
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