report definition of field names

Hal Daume III hdaume@ISI.EDU
Tue, 24 Sep 2002 14:48:37 -0700 (PDT)


Hi All,

I was just reading the report and was confused by something.  In section
3.15 "Datatype with Field Labels", it says:

"A datatype declaration may optionally include field labels for some or
all of the components of the type."

This seems to say that if you have some datatype declaration, you can
label some of the fields and not label others.  Which would imply you
could write something like:

data Foo = Foo { x :: String } Int

or something like that.  However, this disagrees strongly with the
definition in 4.2.1 for the CFG for datatypes:

topdecl   -> data [context =>] simpletype = constrs [deriving]
constrs   -> constr1 | ... | constrn
constr    -> con [!] atype1 ... [!] atypek
           | (btype | !atype) conop (btype | !atype)
           | con { fielddecl1 , ... , fielddecln }
fielddecl -> vars :: (type | ! atype)

where clearly you are not allowed to mix them.

The only other interpretation that I can get out of the sentence in 3.15
is that you can use field labels for some constructors and not for other,
but that you must choose which one you want to use per constructor.  This
is certainly consistent with implementations and with the CFG.  however,
in the discussion of labelled field in section 4.2.1, it says:

"A data constructor of arity k create an object with k component"

which clearly implies that the definition of "component" has to do with
the fields within a particular constructor, not with different
constructors for the same datatype.

I suggest (I know it's late) the following change to 3.15:

Replace:
     "A datatype declaration may optionally include field labels for some
      or all of the components of the type."
With:
     "A datatype declaration may optionally include field labels.  Each
      constructor must use either labelled fields or unlabelled fields,
      but different constructors of a datatype may use whichever,
      independent of the other constructors."

Or something like that.

 - Hal
      

--
Hal Daume III

 "Computer science is no more about computers    | hdaume@isi.edu
  than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume