update code

This commit is contained in:
Yann Esposito (Yogsototh) 2018-09-28 17:57:50 +02:00
parent a9c3ac93c1
commit 123b8a632e
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
6 changed files with 28 additions and 17 deletions

View file

@ -0,0 +1,2 @@
*.hi
*.o

View file

@ -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]

Binary file not shown.

View file

@ -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

View 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)

View file

@ -0,0 +1,3 @@
#!/bin/bash
stack ghc --package parallel -- -threaded -O2 005_purete_par.hs