Skip to content

Latest commit

 

History

History
163 lines (132 loc) · 8.79 KB

README.md

File metadata and controls

163 lines (132 loc) · 8.79 KB

Book – Parallel and Concurrent Programming in Haskell

Haskell project The parconc-examples\ directory contains Haskell examples presented in Marlow's book "Parallel and Concurrent Programming in Haskell" (O'Reilly, 2013).

In the following we present the two examples rpar and strat.

🔎 The source archive with the original code examples is available from repository simonmar/parconc-examples on GitHub (see also the original README.md).

We can build/run code examples in directory parconc-examples\ in several ways. For instance we have the following configuration files for example rpar:

Build tool Build file Parent file
build.bat parconc-examples.cabal 1 n.a.
cabal.exe parconc-examples.cabal n.a.
mvn.cmd pom.xml pom.xml
stack.exe stack.yaml n.a.

rpar Example

Cabal

> cabal clean & cabal run rpar
Resolving dependencies...
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
 - parconc-examples-0.4.7 (exe:rpar) (first run)
Configuring executable 'rpar' for parconc-examples-0.4.7..
Preprocessing executable 'rpar' for parconc-examples-0.4.7..
Building executable 'rpar' for parconc-examples-0.4.7..
[1 of 1] Compiling Main             ( src\rpar.hs, H:\parconc-examples\dist-newstyle\build\x86_64-windows\ghc-8.10.7\parconc-examples-0.4.7\x\rpar\build\rpar\rpar-tmp\Main.o )
Linking H:\parconc-examples\dist-newstyle\build\x86_64-windows\ghc-8.10.7\parconc-examples-0.4.7\x\rpar\build\rpar\rpar.exe ...
rpar: user error (Pattern match failure in do expression at src\rpar.hs:18:3-5)

Stack

> stack clean && stack build

Batch

Command build clean run builds and executes the Haskell program src\rpar.hs:

> build clean run
time: 0.00s
(24157817,14930352)
time: 3.76s

With option -debug command build also displays several useful informations, e.g.

  • Execution environment : display actual value of properties, options, variables.
  • Conditional processing : compile only if target is older than sources.
  • Execution transparency : the executed console command with options and arguments can be copied/run separately.
> build -debug clean run
[build] Options    : _TIMER=0 _VERBOSE=0
[build] Subcommands: _CLEAN=1 _COMPILE=1 _DOC=0 _RUN=1
[build] Variables  : _EXEC=rpar
[build] rmdir /s /q "H:\parconc-examples\target"
[build] "ghc.exe" -Wall -Wincomplete-uni-patterns -hidir "H:\parconc-examples\target\gen" -odir "H:\parconc-examples\target\gen" -threaded -i"H:\parconc-examples\lib\monad-par-0.3.5:H:\parconc-examples\lib\parallel-3.2.2.0:H:\parconc-examples\lib\timeit-2.0" -XHaskell2010 -o "H:\parconc-examples\target\rpar.exe" -Rghc-timing H:\parconc-examples\src\rpar.hs
[1 of 4] Compiling Control.Parallel ( ... )
[2 of 4] Compiling Control.Seq      ( ... )
[3 of 4] Compiling Control.Parallel.Strategies ( ... )
[4 of 4] Compiling Main             ( ... )
Linking H:\parconc-examples\target\rpar.exe ...
<<ghc: 437400616 bytes, 124 GCs, 10149480/33063872 avg/max bytes residency (10 samples), 86M in use, 0.000 INIT (0.001 elapsed), 0.328 MUT (13.692 elapsed), 0.188 GC (0.305 elapsed) :ghc>>
[build] "H:\parconc-examples\target\rpar.exe" 1
time: 0.00s
(24157817,14930352)
time: 3.76s
[build] _EXITCODE=0

strat Example

Cabal

> cabal clean & cabal run strat
Resolving dependencies...
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
 - parconc-examples-0.4.7 (exe:strat) (first run)
Configuring executable 'strat' for parconc-examples-0.4.7..
Preprocessing executable 'strat' for parconc-examples-0.4.7..
Building executable 'strat' for parconc-examples-0.4.7..
[1 of 1] Compiling Main             ( src\strat.hs, H:\parconc-examples\dist-newstyle\build\x86_64-windows\ghc-8.10.7\parconc-examples-0.4.7\x\strat\build\strat\strat-tmp\Main.o )
Linking H:\parconc-examples\dist-newstyle\build\x86_64-windows\ghc-8.10.7\parconc-examples-0.4.7\x\strat\build\strat\strat.exe ...
(14930352,24157817)

Stack


Batch

With option -exec:strat command build builds and executes the Haskell application strat:

> build -verbose -exec:strat clean run
Delete directory "target"
Compile Haskell source files to directory "H:\parconc-examples\target"
Execute Haskell program "target\strat.exe"
(14930352,24157817)

With option -debug command build also displays several useful informations, e.g.

  • Execution environment : display actual value of properties, options, variables.
  • Conditional processing : compile only if target is older than sources.
  • Execution transparency : the executed console command with options and arguments can be copied/run separately.
> build -debug -exec:strat run
[build] Options    : _TIMER=0 _VERBOSE=0
[build] Subcommands: _CLEAN=0 _COMPILE=1 _DOC=0 _RUN=1
[build] Variables  : "CABAL_DIR=%APPDATA%\cabal"
[build] Variables  : "GHC_HOME=C:\opt\ghc-8.10.7"
[build] Variables  : _EXEC=strat
[build] 20210921191143 Target : "H:\parconc-examples\target\strat.exe"
[build] 20200910092417 Sources: "H:\parconc-examples\src\*.hs"
[build] _ACTION_REQUIRED=0
[build] "H:\parconc-examples\target\strat.exe" 1
(14930352,24157817)
[build] _EXITCODE=0

Footnotes

[1] build.bat

In project Factorial the batch file build.bat reads several properties directly from Factorial.cabal if the Cabal project file is present; for instance: name, synopsis, version, executable, main-is, ghc-options and default-language.

mics/May 2024