datatype constructor as syntax

Thant Tessman <[email protected]>
Newsgroups gmane.comp.lang.ml.mlton.user
Message-ID <[email protected]>
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.

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 managed to figure out that at least one reason might be because constructors are used in pattern matching:

	- val i = bar 3;
	val i = bar 3 : mytype

	- val (bar j) = i;
	val j = 3 : int

My question: Is this the reason? I guess this features is cool, but one unnerving thing about it is that this kind of pattern matching is inherently non-exhaustive.

Thanks much,

-thant

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.