Skip to content

The documented FlexibleInstances grammar is incorrect and also out of date

Summary

The GHC User's Guide contains a simplified formal grammar of instance declarations in presence of FlexibleInstances:

https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/instances.html#formal-syntax-for-instance-declaration-types

The left-hand side of the production

arg_type ::= <empty>
          |  arg_type arg_types

therein is erroneous, it should be defining arg_types (plural) instead.

Another problem is that the grammar is out of date in that it doesn't allow type applications in instance head. This is legal nowadays:

type  C :: forall k. k -> Constraint
class C a
instance C @Type Int

Proposed improvements or changes

The missing letter s should definitely be inserted.

As for the type applications in instance heads, they should should be documented somewhere. I don't see them mentioned in the TypeApplications section. I'm not sure if the above-mentioned grammar is meant to showcase the full syntax of instance declarations with all extensions enabled, or only what FlexibleInstances brings. In the former case it should be extended with type applications, in the latter it doesn't need the infix operator case nor multiple class parameters.

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