I am a haskell beginner, and I recently read about strictness analysis on the haskell wiki. GHC user's guide reads:
The strictness analyser figures out when arguments and variables in a function can be treated 'strictly' (that is they are always evaluated in the function at some point).
I've also read about when strictness can be inferred, in general. However, as a beginner, I am not always sure if ghc actually treats my piece of code, which I intended to be strict, as being strict.
Currently, I have no other way to find out whether the strict analysis is taking place than feeding the program with large data.
Is there any way to ask ghc if can infer a given code to be strict?
The only way I've seen actually verify that GHC has inferred strictness is to read an intermediate representation of the compiled program called Core.
Some resources on learning to read Core output:
However, another approach is to simply tell GHC which expressions should be evaluated strictly, for example, by using the BangPatterns
language extension or the seq
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With