BT

Haskell Can Now Do Strict Evaluation by Default

| by Sergio De Simone Follow 14 Followers on Nov 28, 2015. Estimated reading time: 1 minute |

A new Strict language extension to Haskell aims to make it easier to use Haskell for code that is meant to be mostly strict, i.e., evaluated in a non-lazy manner. The feature was recently merged into GHC’s git HEAD and will be included in GHC’s next release.

The -XStrict and -XStrictData pragmas will switch Haskell behaviour on a per-module basis so functions, data types, and bindings are evaluated strictly and not lazily. -XStrictData is a subset of -XStrict and only affects bindings. Thus, when -XStrict is specified,

data T = C a
f x = ...
let x = ...

is actually interpreted as if it were:

data T = C !a
f !x = ...
let !x

Lazy-evaluation can be reinstated on a case-by-case basis by prepending ~ to variable names. So, these pragmas sort of reverse Haskell’s default behaviour, where evaluation is lazy and can be made strict by using ! in front of names.

As Adam Sandberg Ericsson, implementor of the strict pragmas, noted, this feature will not turn Haskell into a strict language, rather it provides a means to write better looking code when strict evaluation is required. He also adds that the patch comprises 500 lines of code which mostly have to do with extending Haskell so it allows strict bindings to be recursive and polymorphic and to a lesser extent with inserting strictness annotations where required.

Johan Tibell, Google engineer under whose supervision Sandberg Ericsson implemented the strict feature, further clarified the benefits that it will provide, namely reducing syntactic noise and chances of errors when using the bang in Haskell code that should be mostly strict, and understanding how changing Haskell’s default behaviour may affect performance. Tibell also remarks that adopting StrictData will likely bring only modest change to a code base that is already using strict constructor fields. On the other hand, adopting Strict will presumably imply lots of changes in existing code bases, so it should be taken with more care.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT