-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unsigned integer types #17
Comments
this suggestion, at least, does not sound hard to implement!
|
First, decimal word literals are supported (e.g., 0w10). The reason for the "0w" prefix is similar to the reason the SML requires real literals to have a decimal point. The problem with this suggestion is that there is no hardware support for underflow checking, so you would take a performance hit on subtraction and negation. Since subscripting already checks for negative indices, I don't think that we gain much from such a type. BTW, exceptions on integer overflow are a real pain for deterministic parallel computation, because so much code can potentially raise an exception, but is very unlikely to do so. I'm not sure if the right choice is to relax the requirement for sequential semantics where exceptions are concerned, or switch to C-style integer arithmetic. |
Many functions only make sense when applied to nonnegative integers (e.g.,
List.nth
). However, because Standard ML doesn't have an unsigned integer type, one has to use signed integers, and then hopefully not forget to implement a nonnegativity check. I'd like a proper unsigned integer type, so that the check is performed automatically and at compile-time, rather than manually and at runtime.I can anticipate an argument that I should use the existing
word
type. However, as useful as theword
type may be for certain use cases (e.g., processing files with non-textual contents), it isn't a good general-purpose unsigned integer type for the following reasons:word
constants are represented textually as hexadecimals preceded by0w
. To get the more familiar decimal representations of numeric values, one would have to translate back and forth betweenword
andint
all over the place.Unsigned integers should be provided in modules with the usual
INTEGER
signature, subject to the following constraints:minInt
is alwaysSOME 0
abs
is the identity functionsign
never returns~1
~
raisesOverflow
if its argument isn't0
-
raisesOverflow
if its first argument is less than the seconddiv
andquot
are the same functionmod
andrem
are the same functionThe text was updated successfully, but these errors were encountered: