GHC allows function arrow (->) as data constructor
As was pointed out in this SO question, GHC appears to incorrectly accept (->)
as a valid "consym" in data
declarations. That is, the following code compiles:
data Type
= TBool
| TInt
| (->) Type Type
though attempts to use the constructor are correctly rejected as parse errors:
wontwork ((->) a b) = (->) b a -- both "->" are parse errors
The expected behavior is that, since ->
doesn't start with a colon, it ought to be rejected as a parse error.
I can duplicate this with GHC 8.6.5 and the latest HEAD.
The issue seems to be in tyConToDataCon
which as per the Note "Parsing data constructors is hard" reinterprets a potential type constructor expression as a data constructor expression. It checks the validity of the constructor with isLexCon
which calls isLexConSym
, which specifically permits ->
in addition to constructors that start with a colon (startsConSym
).