Skip to content

Flag for allowing bindings at the end of do blocks

Motivation

I want the following code to compile with a warning:

do
  doSomething
  a <- someFunction

Currently it errors out like so:

The last statement in a 'do' block must be an expression

This is unfortunate, because it means that Haskell Language Server doesn't get the types for any of the things in the do block until I put a undefined at the last line of the do block to make it pass the compile stage this error is thrown in.

It would be great if there was a flag to, similarly to -fdefer-type-errors, allow the compilation to continue in the presence of the incorrect program, while emitting a warning.

Proposal

Add a flag something like -fdo-ends-with-a-hole that will make these do blocks return undefined so they will compile in development.

I don't think this is a "GHC Proposal" kind of change, in that it should be gated behind a flag.

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