Skip to content

Notes on The Standard ML Basis Library

arata, mizuki edited this page Nov 15, 2022 · 10 revisions

structure General

The General structure

unit

The type unit should be an alias for {}, not an opaque type.

signature REAL

The REAL signature

min / max

The document does not specify the handling of the signed zeroes. LunarML tries to honor the sign of zero. i.e.

min (0.0, ~0.0) = min (~0.0, 0.0) = ~0.0
max (0.0, ~0.0) = max (~0.0, 0.0) = 0.0

toManExp

The condition on man should be "1.0 <= |man| * radix < radix".

realRound

The document does not explicitly say what realRound should do in the case of a tie. LunarML breaks tie by choosing the nearest even integer (like round does).

fromInt / fromLargeInt

The document says

If the absolute value of i is larger than maxFinite, then the appropriate infinity is returned.

but it should be something like "If the absolute value of i is equal to or larger than maxFinite + 0.5 ulp (in the case of the current rounding mode is TO_NEAREST), then ...".

I mean, the program

val maxFinite = IntInf.<< (0x1fffffffffffff, 0w1023 - 0w52);
print (Real.fmt (StringCvt.SCI (SOME 17)) (Real.fromLargeInt (maxFinite + 1)) ^ "\n");

should print a finite value.

fmt (SCI _)

The negative sign on the exponent part should be allowed:

[~]?[0-9].[0-9]+?E[~]?[0-9]+
                  ^^^^

signature CHAR

The CHAR signature

toString

toString does not say what to do if the character code cannot be expressed by four hexadecimal digits (i.e. ord x >= 0x10000). LunarML plans use \U<eight hex digits> format.

scan / fromString

Should accept \U<eight hex digits>.

toCString

toString does not say what to do if the character code cannot be expressed by three octal digits (i.e. ord x >= 512). LunarML plans to use \u<four hex digits> or \U<eight hex digits> format.

fromCString

Should accept \u<four hex digits> and \U<eight hex digits> if the value satisfies the condition (x >= 0xA0 andalso not (x >= 0xD800 andalso x <= 0xDFFF)) orelse x = 0x24 orelse x = 0x40 orelse x = 0x60 (see C's spec).

signature STRING

The STRING signature

scan

The type of scan should be

val scan : (Char.char, 'a) StringCvt.reader -> (string, 'a) StringCvt.reader
         (* ^^^^^^^^^ *)

rather than

val scan : (char, 'a) StringCvt.reader -> (string, 'a) StringCvt.reader
         (* ^^^^ *)

Clone this wiki locally