0

What does the exclamation mark mean in this Haskell data declaration:

data Sample = First !Integer | Second !String
norq
  • 1,404
  • 2
  • 18
  • 35
  • It's a bang pattern. It means that the construct is string, so that `First undefined == undefined`. – Bakuriu Jul 08 '16 at 17:01

1 Answers1

2

It makes this field strict - see here

if you add this to the field you make sure that the value is evaluated when you use the constructor - it's usually helpful to avoid space-leaks (from a huge thunk-chain)

if you use GHC8 you can have this by default if you use the Strict or StrictData pragma

Random Dev
  • 51,810
  • 9
  • 92
  • 119