Home > Mobile >  What does the symbol `!` mean in type declarations in Haskell?
What does the symbol `!` mean in type declarations in Haskell?

Time:11-24

In my studies of Haskell, I see the symbol ! used in type declarations. See an example:

data Foo = MkFoo
  { _bar :: !Bar
    , ...
  }

My question is: why is it used and what is the difference to a declaration without it?

CodePudding user response:

Fields marked with an exclamation point are made strict at the site of applications of the associated constructor. For example, your data declaration would be exactly the same as without the ! but writing the following kind of thing everywhere your code uses MkFoo:

bar `seq` MkFoo { _bar = bar }

Full details are in the Report.

  • Related