Skip to content

Change GHC.Hs.* so boundary betwen function binds and pattern binds matches Haskell Report

@int-index described the issues better than myself in the thread for https://github.com/ghc-proposals/ghc-proposals/pull/254, so I will paraphrase.

The standard says:

  • x = 5 is a PatBind

  • x :: Int = 5 is a PatBind

The GHC implementation does not match this specification at the moment:

  • x = 5 is a FunBind (in GHC)

  • x :: Int = 5 is a PatBind (in GHC)

Why is that? Here are some comments from GHC sources:

Reason 1: Special case for type inference: see 'TcBinds.tcMonoBinds'.
Reason 2: Instance decls can only have FunBinds, which is convenient.
          If you change this, you'll need to change e.g. rnMethodBinds

When a signature is added to a variable binding, it is interpreted as a pattern binding, as function bindings cannot have signatures:

x :: Int = 5  -- accepted as PatBind, cannot be a FunBind due to the signature!

However, with Proposal 228 (tracking issue #18203) accepted, we do have signatures in function bindings, and it is a hard sell that x = 5 is a FunBind while x :: Int = 5 is a PatBind.

By making GHC match the spec, those can both be PatBinds. Then we could drop the strictness flag from FunBind, which frankly does not belong there.

However, we need to come up with solutions to the Reason 1 and Reason 2 from that GHC comment. Both of them sound more like engineering issues than something fundamental, so I think we can pull this off?

#1474 (closed) is a (currently stale) attempt at doing this.

Edited by John Ericson
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information