haskell / happy

The Happy parser generator for Haskell
Other
276 stars 84 forks source link

Add examples and test for type signatures on parametrized productions #147

Open harpocrates opened 5 years ago

harpocrates commented 5 years ago

The current user manual (for version 1.19.12) has this to say about parametrized productions

A drawback of the current implementation is that it does not support type signatures for the parameterized productions, that depend on the types of the parameters. We plan to implement that in the future---the current workaround is to omit the type signatures for such rules.

This is flat out wrong. Parametrized productions have (for at least several versions) supported type signatures. Examples:

many(a) :: { [a] }
  :                        { [] }
  | some_rev(a)            { reverse $1 }

some_rev(a) :: { [a] }
  :  a                     { [$1] }
  | some_rev(a) a          { $2 : $1 }

then(a, b) :: { (a,b) }
  : a b                    { ($1, $2) }

To fix:

This is somewhat important since there is also bad advice floating about the internet suggesting people use _ to work around this (see #141 for instance).