Is there any reason for not allowing:

> data Test = Test {}

in Haskell?  I am generating programs where I pattern match on this
constructor: (an artificial example follows)

> main = print (case Test {} of Test {} -> True)

and am currently forced to make a special case of no fields, and
instead to write:

> data Test = Test

for ghc (2.08) and Hugs 1.4 (Jan98) and:

> data Test = Test {dummy :: Void}

for hbc (0.9999.4) (which complains about using field selection on a
constructor that was not defined with fields, which is
understandable).  nhc13 fails on either as it fails on pattern
matching a construction with no fields against a pattern with no
fields. :-(

I see no reason for not allowing an empty list of fields in a data
declaration.

Cheers,

Graeme.

PS. Haskell 1.4 Report reference, Section 4.2.1:

opdecl -> data [context =>] simpletype = constrs [deriving] 
...
constrs -> constr1 | ... | constrn 
constr -> ...
        | con { fielddecl1 , ... , fielddecln }    (n>=1) 
                                                   ^^^^^^



Reply via email to