[MLton] Unicode... again
Andreas Rossberg
AndreasRossberg at web.de
Sun Feb 11 06:21:01 PST 2007
From: "skaller" <skaller at users.sourceforge.net>
>
> I don't think I like the idea of 'infering' a string or char
> type. What is the type of:
>
> "A"
>
> ?? If it is 8 bit but
>
> "\u0123"
>
> is 32 bit just because it happens to contain a character that
> can't be represented as an ordinary Char I'm not sure I like it.
> I may want
>
> "A"
>
> to be 32 bit, and I may want some strong to be forced to be
> 8 bit. I think I'm probably confused here ..
The idea is not to infer the type from the string, but from how the string
is used. IOW, you treat string literals as overloaded, and once overloading
resolution has yielded a specific type you check that the string can
actually be represented in that type.
And actually, SML already requires that. For example,
fun f n = n + 300
is ok (+ defaults to int), but
fun f (n : Int8.int) = n + 300
will make the compiler complain about the int literal being out of range.
According to the language definition, the same idea applies to strings,
except that no SML implementation really supports more than one string type
so far.
I don't think there is any practical problem with this approach.
- Andreas
More information about the MLton
mailing list