Community feedback on wildcard binders in type declarations

Have you ever written a type synonym with an unused type variable?

type Const a b = a     -- b is unused on the RHS

Well, maybe not. But who’s to say the day won’t come? And then it’d be nice to have wildcards instead of introducing an unused variable

type Const a _ = a

This is the subject of a GHC Proposal amendment I’ve written a few days ago: #641. It bundles a few more changes for added generality, e.g. nested parentheses and nested kind annotations

type S ((a)) ((b :: k1) :: k2) = <rhs>

This is perhaps not as useful (if not to say useless) but it makes the grammar more regular in my opinion, so I’ve opted to include it (full reasoning in the PR description).

The change will affect GHC API and template-haskell AST, so I don’t want it to fly under the radar.

7 Likes

Personally I think I’m a bit not sold on the _ as a valid symbol here; insofar as I think of _ as also being related to typed holes, and that doesn’t make sense here.

I understand the motivation; and I think some symbol probably makes sense, but I’m not sure about _.

_ on the left of an = sign is just a wildcard, like it is in function definitions. type Const _ b = b corresponds directly to const _ b = b.

True I suppose that’s fair.

1 Like