Re: datatype constructor as syntax

Andreas Rossberg <[email protected]>
Newsgroups gmane.comp.lang.ml.mlton.user
Message-ID <[email protected]>
On Jan 1, 2014, at 23:34 , Thant Tessman <[email protected]> wrote:
>> 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;

It can be exhaustive for other datatypes:

  datatype time = TIME of real
  val TIME t = f()

> 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:

It is mandatory that inexhaustive bindings produce a warning, _except_ on the toplevel (try “let val bar j = i in j end” for contrast). This presumably is to make deconstructing known values in the REPL a less annoying experience (which MLton doesn’t have). Clearly, though, the whole REPL focus of the Definition is an anachronism.

/Andreas

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.