Using the Haskell Runtime System options

The Runtime System (RTS) in Haskell configures special options such as scheduling, profiling, and managing storage for a compiled Haskell program. In order to write multithreaded code, we must specify our own RTS options as outlined in this recipe.

For further reading, the GHC Commentary on the official Haskell Wiki web page has a very detailed explanation of the runtime system available at https://ghc.haskell.org/trac/ghc/wiki/Commentary/Rts.

How to do it…

Open a terminal, compile a code, and run it using the RTS option. Imagine that our file is named Main.hs, and issue the following commands:

$ ghc -O2 --make Main.hs -threaded -rtsopts 
$ ./Main  +RTS -N2

How it works…

In order to make use of multiple threads, ...

Get Haskell Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.