Re: datatype constructor as syntax
Thant Tessman <[email protected]>
| Newsgroups | gmane.comp.lang.ml.mlton.user |
|---|---|
| Message-ID | <[email protected]> |
Thank you very much for the confirmation and the very interesting elaboration.
> As far as context-freeness, note pretty much all languages are NOT
> context free. A variable that is used has to be bound somewhere, and
> that is not a context-free condition.
Of course it's an error to refer to an unbound variable, but doesn't necessarily have to be parsing error. My interest at the moment is specifically in context-free grammars, or rather, the reasons grammars often aren't.
> I don't understand what you mean by
> ... this kind of pattern matching is inherently non-exhaustive.
To reiterate the example:
datatype mytype = foo | bar of int;
On the one hand, this is exhaustive:
case i of
foo => "foo"
| bar j => "bar";
But the use of constructors in mere variable declaration patterns without the case can't be exhaustive:
val (bar j) = i;
Or at least I can't see how.
On top of that, when I enter this interactively in SML/NJ, there is no warning. However, I just tried it with MLton, and it does indeed produce a warning:
Declaration is not exhaustive.
missing pattern: foo
in: bar j = i
It seems that the designers of SML decided that pattern matching would include both product types and sum types, and that the pattern mechanism for binding variables would be the same as that for case statements, and that this was considered more valuable than outlawing non-exhaustive variable binding by not providing for sum type pattern matching in that case.
Just trying to understand the though process behind the design. Thanks,
-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