Reputation: 16148
I am new to Haskell and today I read though the OpenGL source code and I found this
data VertexArrayDescriptor a =
VertexArrayDescriptor !NumComponents !DataType !Stride !(Ptr a)
deriving ( Eq, Ord, Show )
I tried to search for it and found http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/bang-patterns.html but it is probably something different.
What does it do? What is it for?
Upvotes: 7
Views: 1443
Reputation: 8091
It is to make it easier to write strict programs in Haskell and makes strictness more convenient for the developer to avoid being forced into being 'lazy' or non-strict just for convenience.
Take for example :
> data PNat = PZero | PSuc !Nat deriving Show
The bang declares that PSuc
is strict in its argument, i.e. PSuc bottom = bottom (where bottom is a non-terminating expression).
It is to indicate strictness in patterns:
f !x !y = x + y
Good Reference : https://ghc.haskell.org/trac/haskell-prime/wiki/BangPatterns
Upvotes: 7