Re: datatype constructor as syntax

Matthew Fluet <[email protected]>
Newsgroups gmane.comp.lang.ml.mlton.user
Message-ID <CAMrhFL5=NE-kjZpxDs-AJ6A4JUw9-n=mMgi165kALA1mx9M1qA@mail.gmail.com>
On Sat, Dec 28, 2013 at 1:36 PM, Thant Tessman <[email protected]> wrote:
>
> I have a rather esoteric question about Standard ML. I hope I'm not being too annoying asking it in a forum specific to MLton.

Questions about SML are quite welcome on the MLton mailing lists.

> A datatype declaration introduces a new sum type and one or more constructors:
>
>         datatype mytype = foo | bar of int;
>
> On the one hand, the constructors smell syntactically like regular old functions:
>
>         - bar;
>         val it = fn : int -> mytype
>
>         - bar 3;
>         val it = bar 3 : mytype
>
> On the other, they somehow become syntax. With the above defined:
>
>         - val bar = 23;
>         stdIn:24.5-24.8 Error: data constructor bar used without argument in pattern
>
> That is, I can not shadow the old constructor version of bar with a new variable binding. This implies that with respect to constructors, SML's grammar is not context-free.

I'm not quite sure if the following is exactly what you were thinking
about, but it is true that there are certain kinds of program errors
that would be identified as syntax errors in languages like OCaml and
Haskell (that require a lexical distinction between variables and
constructors), but are identified as type-checking errors in Standard
ML (that does not require a lexical distinguish between variables and
constructors).  Since the constructor or non-constructor status of a
variable is determined by its binding occurrence, and, as pointed out,
matching definitions to uses isn't context-free, then, yes, one cannot
check the proper use of constructors with a context-free grammar.
But, even for languages like OCaml and Haskell, one cannot check the
proper use of constructors with a context-free grammar, since proper
use would require that all applications were applied to the right
number of arguments (of the right type), and that certainly isn't
context-free.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.