Re: datatype constructor as syntax
Henry Cejtin <[email protected]>
| Newsgroups | gmane.comp.lang.ml.mlton.user |
|---|---|
| Message-ID | <CAPKXxCpW9C-8LJ8FrHRLAaJm_=Yg6BGuGZfkAqAB4QcrhdU20g@mail.gmail.com> |
As you guessed, constructors of datatypes are not just values, they are
syntactically special because they mean something special in a pattern.
Note, it is possible (although awkward and a kludge) to rebind name
which is a constructor to a value. The trick is that in a `val rec'
binding, the variable being bound position is NOT a pattern. Of course
the right hand side of a val rec must be a function, so you have to
first rebind it to a function and then bind it again to the value you
want.
Hence, the following is legal:
datatype mytype = foo | bar of int
val rec bar = fn () => ()
val bar = 23
Of course this would mean that you could not use bar (the constructor)
in the right-hand side of the value that you want bar (the value) bound
to. To handle that case, you have to use some other variable name:
local
val tmp = <arbitrary expression>
rec bar = fn () => ()
in
val bar = tmp
end
where <tmp> is any variable name which is NOT a constructor in the outer
scope.
As I said, definitely a kludge.
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.
I don't understand what you mean by
... this kind of pattern matching is inherently non-exhaustive.
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