Is it possible to turn off lazy evaluation in Haskell?
Is there a specific compiler flag of library to facilitate this?
I wanted to try something new with
The strict-identity
package has a strict version of the Identity
monad.
You can find it here: https://hackage.haskell.org/package/strict-identity
The usage would look something like this:
foo = runStrictIdentity $! do
x <- f a b
y <- g x y
return $! x + y
Each time return
or bind >>=
is used, the two parts are evaluated using seq
, giving a reasonable guarantee of strictness provided your data structure isn't too deep. This works, for i.e. numbers and basic structures.