ghc
ghc copied to clipboard
Consider removing `One` and `Many` as pattern synonyms
The One and Many pattern synonyms are, on the surface, a convenient conceit: we like to think of multiplicities as being (mostly) either One or Many, and this is indeed the surface we present to the programmer.
But I claim this code design has several downsides:
- Multiplicities really are full types. Matching against
OneandManyis never complete, and it shouldn't look like it is. - Matching against
OneandManydoes real, non-trivial work. Yet this is not apparent from usage sites. - Searching code is made harder: I sometimes want to find introductions of these and I sometimes want to find eliminations of these. If they're written identically, grep doesn't help me here.
- A newcomer to the codebase is even more likely to have a hard time here.
- Pattern synonyms shine when they bind variables -- pattern synonyms that bind variables can significantly simplify code. But these don't and could easily be replaced with a guard.
I thus advocate that we remove these pattern synonyms and instead use oneDataConTy, manyDataConTy, isOneDataConTy, and isManyDataConTy.
To be fair, I don't feel very strongly about this, but I would like to start the conversation. I'm happy to implement the change myself if we agree.
I think that we want and need the One and Many pattern synonyms (or whatever they are replaced with) to be used rather freely. Because of the fact that we want the type system to understand the algebraic rules for them.
My personal feeling is that pattern synonyms are the most convenient representation, in these circumstances.
But, likewise, I won't shed tears if we go the other way.