简体   繁体   中英

How to tell if strictness is actually inferred by GHC?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM