Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if strictness is actually inferred by GHC?

Tags:

haskell

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?

like image 437
Yosh Avatar asked Nov 13 '14 02:11

Yosh


1 Answers

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:

  • Reading GHC Core
  • http://www.scs.stanford.edu/11au-cs240h/notes/ghc-slides.html#(1)

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.

like image 125
ErikR Avatar answered Nov 13 '22 22:11

ErikR