Opened 6 years ago

Closed 4 years ago

#8347 closed feature request (fixed)

Add a Strict LANGUAGE pragma

Reported by: tibbe Owned by: adamse
Priority: normal Milestone: 8.0.1
Component: Compiler Version: 7.6.3
Keywords: Cc: adamse, tibbe
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: DsStrictData, DsStrictLet, DsStrictFail, DsStrictWarn
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D1033, Phab:D1142
Wiki Page:

Description (last modified by adamse)

A Strict LANGUAGE pragma would allow us to experiment with writing in a strict sub-language. Since this pragma works on a per module basis, it needs to be modular. I propose the following semantics:

  • Patterns are strict at the top-level, as if they had a top-level bang, unless an explicit ~ is used to make the pattern lazy.
  • Functions evaluate their parameters to WHNF.
  • Data type fields are strict (as if they had a bang-pattern).

Design page: StrictPragma

Change History (15)

comment:1 Changed 6 years ago by tibbe

Owner: set to tibbe

comment:2 Changed 5 years ago by tibbe

comment:3 Changed 4 years ago by thomie

Differential Rev(s): Phab:D1033
Milestone: 7.12.1


Haskell doesn't allow for ~ patterns in data constructor definitions today: we'll add support for such definitions and have it give the current lazy behavior.

From Phab:D1033, I understand that using ~ in data constructor definitions without -XStrictData will be the error:

"Lazy annotation (~) without StrictData"

Maybe it would be useful to be able to compile a module both with and without -XStrictData, to compare performance differences. In that case this new ~ syntax should be under a different language pragma. Has this been given consideration?

comment:4 Changed 4 years ago by tibbe

I would pile on even more stuff on ​Phab:D1033, but we could add a -XExplicitLazyFields language pragma that's implied by -XStrictFields in a separate commit.

comment:5 Changed 4 years ago by Ben Gamari <ben@…>

In f842ad6/ghc:

Implementation of StrictData language extension

This implements the `StrictData` language extension, which lets the
programmer default to strict data fields in datatype declarations on a
per-module basis.

Specification and motivation can be found at

This includes a tricky parser change due to conflicts regarding `~` in
the type level syntax: all ~'s are parsed as strictness annotations (see
`strict_mark` in Parser.y) and then turned into equality constraints at
the appropriate places using `RdrHsSyn.splitTilde`.

Updates haddock submodule.

Test Plan: Validate through Harbormaster.

Reviewers: goldfire, austin, hvr, simonpj, tibbe, bgamari

Reviewed By: simonpj, tibbe, bgamari

Subscribers: lelf, simonpj, alanz, goldfire, thomie, bgamari, mpickering

Differential Revision:

GHC Trac Issues: #8347

comment:6 Changed 4 years ago by adamse

Description: modified (diff)
Differential Rev(s): Phab:D1033Phab:D1033, Phab:D1142
Owner: changed from tibbe to adamse

comment:7 Changed 4 years ago by simonpj

Cc: adamse tibbe added

If this is committed, can we close it?

However, I wish there were a few regression tests to demonstrate the feature.


comment:8 Changed 4 years ago by tibbe

Only the StrictData part is done. The more general Strict pragma (i.e. also dealing with bindings) is still waiting for review ( If you haven't taken a look already, please do so.

comment:9 Changed 4 years ago by simonpj

OK I'll do that. Still, regression tests for the StrictData part would be good.


comment:11 Changed 4 years ago by adamse

Test Case: DsStrictData

comment:12 Changed 4 years ago by simonpj

Sorry, missed that test. Good!

comment:13 Changed 4 years ago by thoughtpolice


Milestone renamed

comment:14 Changed 4 years ago by Ben Gamari <ben@…>

In 46a03fb/ghc:

Implement the Strict language extension

Add a new language extension `-XStrict` which turns all bindings strict
as if the programmer had written a `!` before it. This also upgrades
ordinary Haskell to allow recursive and polymorphic strict bindings.

See the wiki[1] and the Note [Desugar Strict binds] in DsBinds for
specification and implementation details.


Reviewers: austin, tibbe, simonpj, bgamari

Reviewed By: tibbe, bgamari

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #8347

comment:15 Changed 4 years ago by thomie

Resolution: fixed
Status: newclosed
Test Case: DsStrictDataDsStrictData, DsStrictLet, DsStrictFail, DsStrictWarn
Note: See TracTickets for help on using tickets.