Re: string/char vector type equivalence
Matthew Fluet <[email protected]> Mon, 25 Feb 2013 08:50:21 -0500
| Newsgroups | gmane.comp.lang.ml.mlton.devel |
|---|---|
| Message-ID | <CAMrhFL6Wt5P4TemP9QQaJoPFbFZskmre+zGeXvtovv1aWcmmpg@mail.gmail.com> |
On Wed, Feb 6, 2013 at 11:29 AM, Christopher Cramer < [email protected]> wrote: > On Tue, Feb 05, 2013 at 09:31:56AM -0500, Matthew Fluet wrote: > > I think that the reason that it doesn't is to support > > string constants, but I couldn't quickly see where the necessary type > > equalities were established in the Basis Library implementation and the > > type checker. > > Actually, with some further experimentation, it seems like the fix should > be > rather simple, as this does not compile: > > structure Vector :> sig > eqtype 'a vector > val fromList: 'a list -> 'a vector > end = struct > type 'a vector = 'a vector > val fromList = vector > end > > type 'a vector = 'a Vector.vector > val vector = Vector.fromList > > val foo: char vector = "foo" > val bar: string = vector [#"b", #"a", #"r"] > val _ = foo ^ bar > > Error: opaquevector.sml 12.5. > Pattern and expression disagree. > pattern: [char vector] > expression: [string] > in: (foo): char vector = "foo" > Error: opaquevector.sml 13.5. > Pattern and expression disagree. > pattern: [string] > expression: [char vector] > in: (bar): string = vector [#"b", #"a", #"r"] > Error: opaquevector.sml 14.13. > Function applied to incorrect argument. > expects: [string] * _ > but got: [char vector] * _ > in: ^ (foo, bar) > > Since there are no vector literals, it should be OK to do something > like this in the Basis Library without touching the type checker. > That is a very nice observation. I'll investigate that a little more, although I seem to recall that we couldn't use as many opaque signature matches as we wished, because of the various ways in which some types are used in signatures. ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_d2d_feb _______________________________________________ MLton-devel mailing list [email protected]; [email protected] https://lists.sourceforge.net/lists/listinfo/mlton-devel