Re: string/char vector type equivalence
Christopher Cramer <[email protected]> Wed, 6 Feb 2013 11:29:54 -0500
| Newsgroups | gmane.comp.lang.ml.mlton.devel |
|---|---|
| Message-ID | <[email protected]> |
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. ------------------------------------------------------------------------------ Free Next-Gen Firewall Hardware Offer Buy your Sophos next-gen firewall before the end March 2013 and get the hardware for free! Learn more. http://p.sf.net/sfu/sophos-d2d-feb