by Sean P. Miller
The definitions in this file are designed to fulfill the following purposes:
| Signature | Description |
| filter (pred: `a -> bool, seq: [`a]): [`a] | Collects all elements in seq that satisfy pred. |
| foldl (f: `a * `b -> `a, init: `a, seq: [`b]): `a | Left-to-right accumulation of seq. |
| foldr (f: `a * `b -> `b, init: `b, seq: [`a]): `b | Right-to-left accumulation of seq. |
| foreach (f: `a -> void, seq: [`a]): void | Applies f to each element in seq. |
| map (f: `a -> `b, seq: [`a]): [`b] | Returns the results of f applied to each element in seq. |
| zip (xs: [`a], ys: [`b]): [`a * `b] | Pairs corresponding elements of xs and ys. |
| partition (pred: `a -> bool, seq: [`a]): [`a] * [`a] | Returns a pair of sequences (T,F) where T contains the elements in seq that satisfy pred and F contains the rest. |
| generate (gen: void -> `a, count: int): [`a] | Creates a sequence of length count initialized with calls to gen. |
| range (lower: int, upper: int): [int] | Returns all integers in the half-open range [lower, upper). |
| mapMaybe (f: `a -> `b maybe, seq: [`a]): [`b] | A specialized transform that discards Nothing results. |
| merge (cmp: `a * `a -> order, left: [`a], right: [`a]): [`a] | Merges two sequences into ascending order. |
| mergeSort (cmp: `a * `a -> order, seq: [`a]): [`a] | A stable, safe, slower sort. |
| quickSort (cmp: `a * `a -> order, seq: [`a]): [`a] | An unstable, unsafe, faster sort. |
| find (pred: `a -> bool, seq: [`a]): `a maybe | Attempts to find an element in seq that satisfies pred. |
| findAll (pred: `a -> bool, seq: [`a]): [`a] | Collects all elements in seq that satisfy pred. |
| binarySearch (cmp: `a * `a -> order, e: `a, seq: [`a]): `a maybe | Fast lookup for presorted sequences. |
filter (pred: `a -> bool, seq: [`a]): [`a]
(* r1 contains ss with empty strings removed *)
def r1 = filter (lambda (s) { return s <> ""; }, ss);
Parameters:
Returns:
foldl (f: `a * `b -> `a, init: `a, seq: [`b]): `a
Parameters:
Returns:
Notes:
foldr (f: `a * `b -> `b, init: `b, seq: [`a]): `b
Parameters:
Returns:
Notes:
foreach (f: `a -> void, seq: [`a]): void
Parameters:
Notes:
map (f: `a -> `b, seq: [`a]): [`b]
Parameters:
Returns:
zip (xs: [`a], ys: [`b]): [`a * `b]
Parameters:
Returns:
Notes:
partition (pred: `a -> bool, seq: [`a]): [`a] * [`a]
Parameters:
Returns:
generate (gen: void -> `a, count: int): [`a]
Parameters:
Returns:
range (lower: int, upper: int): [int]
Parameters:
Returns:
Notes:
mapMaybe (f: `a -> `b maybe, seq: [`a]): [`b]
(* r1 will be [1,2,4] *)
def r1 = mapMaybe (str2int, ["1", "2", "xx", "4"]);
Parameters:
Returns:
Notes:
merge (cmp: `a * `a -> order, left: [`a], right: [`a]): [`a]
Parameters:
Returns:
Notes:
mergeSort (cmp: `a * `a -> order, seq: [`a]): [`a]
Parameters:
Returns:
Notes:
quickSort (cmp: `a * `a -> order, seq: [`a]): [`a]
Parameters:
Returns:
Notes:
find (pred: `a -> bool, seq: [`a]): `a maybe
Parameters:
Returns:
Notes:
findAll (pred: `a -> bool, seq: [`a]): [`a]
Parameters:
Returns:
Notes:
binarySearch (cmp: `a * `a -> order, e: `a, seq: [`a]): `a maybe
Parameters:
Returns:
Notes:
The definitions in this file are designed to fulfill the following purposes:
Generic exceptions, maybe, and order are also provided.
Note that this file is automatically included in other headers.
| Data Constructor | Type Constructor | Parameterization | Description |
| Arithmetic | BasicException | string | Thrown when various mathematical errata occur. |
| OutOfBounds | BasicException | string | Thrown when a numeric argument is outside expected bounds. |
| Empty | BasicException | string | Thrown when an empty sequence is unacceptable. |
| BadArgument | BasicException | string | Thrown when an argument is malformed. |
| RuntimeFailure | BasicException | string | Thrown when an internal error occurs. |
| Interrupted | BasicException | string | Thrown when blocked operation is interrupted. |
| StackOverflow | BasicException | string | Thrown when stack exhausted. |
| Existential | BasicException | Thrown when Nothing is unacceptable. | |
| Nothing | `a maybe | Represents a failed computation. | |
| Some | `a maybe | `a | Wraps the result of a successful computation. |
| Less | order | Less-than comparison result. | |
| Equal | order | Equal-to comparison result. | |
| Greater | order | Greater-than comparison result. |
| Signature | Description |
| int2str (n: int): string | Produces a human-readable base-ten string from n. |
| int2radix (n: int, radix: int): string | Produces a human-readable base-radix string from n. |
| int2char (n: int): char maybe | Interprets n as a Unicode codepoint. |
| real2str (x: real): string | Produces a human-readable base-ten string from x. |
| getprec (x: real): int | Returns x's precision. |
| setprec (x: real, prec: int): real | Creates a new real with x's value and precision prec. |
| float2str (f: float): string | Produces a human-readable base-ten string from f. |
| str2int (s: string): int maybe | Converts base-ten string s into an integer. |
| str2real (s: string): real maybe | Converts s into a real. |
| str2float (s: string): float maybe | Converts s into a float. |
| sub (s: string, index: int): char | Returns the character from s at position index. |
| substr (s: string, index: int, count: int): string | Returns a substring of s of length count beginning at position index. |
| strlen (s: string): int | Returns the number of characters in s. |
| explode (s: string): [char] | Converts s into an equivalent sequence of characters. |
| char2str (c: char): string | Converts c into an equivalent string. |
| char2int (c: char): int | Returns an integer equal to c's Unicode codepoint. |
| bool2str (b: bool): string | Produces a human-readable string from b. |
| head (seq: [`a]): `a | Returns seq's leftmost element. |
| tail (seq: [`a]): [`a] | Returns seq without its leftmost element. |
| rhead (seq: [`a]): `a | Returns seq's rightmost element. |
| rtail (seq: [`a]): [`a] | Returns seq without its rightmost element. |
| len (seq: [`a]): int | Returns the number of elements in seq. |
| implode (charSeq: [char]): string | Converts charSeq into an equivalent string. |
| split (index: int, seq: [`a]): [`a] * [`a] | Returns (L,R) where L is all elements in seq before position index and R is those at or after index. |
| at (index: int, seq: [`a]): `a | Returns the element in seq at position index. |
| take (count: int, seq: [`a]): [`a] | Returns the first count elements of seq. |
| drop (count: int, seq: [`a]): [`a] | Discards the first count elements of seq and returns the rest. |
| insert (index: int, e: `a, seq: [`a]): [`a] | Returns seq with element e inserted at position index. |
| delete (index: int, seq: [`a]): [`a] | Returns seq without the element at position index. |
| slice (begin: int, end: int, seq: [`a]): [`a] | Returns the subsequence of seq from position begin to position end, inclusive. |
| rev (seq: [`a]): [`a] | Returns seq in reverse order. |
| val (e: `a maybe): `a | Extracts the argument from a maybe construction. |
| isNothing (e: `a maybe): bool | If given Nothing, returns true; else, returns false. |
| isSome (e: `a maybe): bool | If given any Some construction, returns true; else, returns false. |
| compare (a: `a, b: `a): order | Defines a total ordering over most types. |
| send (ch: `a channel, msg: `a): void | Queues msg in FIFO ch. |
| recv (ch: `a channel): `a | Pulls the first available message from ch. |
int2str (n: int): string
Parameters:
Returns:
int2radix (n: int, radix: int): string
Parameters:
Returns:
Exceptions:
int2char (n: int): char maybe
Parameters:
Returns:
Notes:
getprec (x: real): int
Parameters:
Returns:
setprec (x: real, prec: int): real
Parameters:
Returns:
Exceptions:
Notes:
float2str (f: float): string
Parameters:
Returns:
str2int (s: string): int maybe
Parameters:
Returns:
str2real (s: string): real maybe
Parameters:
Returns:
str2float (s: string): float maybe
Parameters:
Returns:
sub (s: string, index: int): char
Parameters:
Returns:
Exceptions:
Notes:
substr (s: string, index: int, count: int): string
Parameters:
Returns:
Exceptions:
Notes:
strlen (s: string): int
Parameters:
Returns:
Notes:
explode (s: string): [char]
Parameters:
Returns:
Notes:
char2str (c: char): string
Parameters:
Returns:
char2int (c: char): int
Parameters:
Returns:
Notes:
bool2str (b: bool): string
Parameters:
Returns:
head (seq: [`a]): `a
Parameters:
Returns:
Exceptions:
tail (seq: [`a]): [`a]
Parameters:
Returns:
Exceptions:
rhead (seq: [`a]): `a
Parameters:
Returns:
Exceptions:
rtail (seq: [`a]): [`a]
Parameters:
Returns:
Exceptions:
len (seq: [`a]): int
Parameters:
Returns:
Notes:
implode (charSeq: [char]): string
Parameters:
Returns:
Notes:
split (index: int, seq: [`a]): [`a] * [`a]
Parameters:
Returns:
Exceptions:
Notes:
at (index: int, seq: [`a]): `a
Parameters:
Returns:
Exceptions:
Notes:
take (count: int, seq: [`a]): [`a]
Parameters:
Returns:
Exceptions:
Notes:
drop (count: int, seq: [`a]): [`a]
Parameters:
Returns:
Exceptions:
Notes:
insert (index: int, e: `a, seq: [`a]): [`a]
Parameters:
Returns:
Exceptions:
Notes:
delete (index: int, seq: [`a]): [`a]
Parameters:
Returns:
Exceptions:
Notes:
slice (begin: int, end: int, seq: [`a]): [`a]
Parameters:
Returns:
Exceptions:
Notes:
rev (seq: [`a]): [`a]
Parameters:
Returns:
Notes:
val (e: `a maybe): `a
Parameters:
Returns:
Exceptions:
isNothing (e: `a maybe): bool
Parameters:
Returns:
isSome (e: `a maybe): bool
Parameters:
Returns:
compare (a: `a, b: `a): order
Parameters:
Returns:
Exceptions:
Notes:
send (ch: `a channel, msg: `a): void
Parameters:
Notes:
recv (ch: `a channel): `a
Parameters:
Returns:
Exceptions:
Notes:
The definitions in this file are designed to fulfill the following purposes:
| Data Constructor | Type Constructor | Parameterization | Description |
| FileNotFound | IOException | string | Thrown when file cannot be found. |
| IOFailure | IOException | string | Thrown when unspecified I/O error occurs. |
| BadFd | IOException | string | Thrown when given invalid file descriptor. |
| BadOpenmode | IOException | string | Thrown when given invalid openmode. |
| Name | Value |
| fd | {loc: string, mode: openmode, id: int} |
| openmode | int |
| Definition | Value |
| MODE_IN: openmode | 1 |
| MODE_OUT: openmode | 1 << 1 |
| MODE_APP: openmode | 1 << 2 |
| MODE_TRUNC: openmode | 1 << 3 |
| STDIN: fd | {loc="<STDIN>", mode=MODE_IN, id=0} |
| STDOUT: fd | {loc="<STDOUT>", mode=MODE_OUT, id=1} |
| STDERR: fd | {loc="<STDERR>", mode=MODE_OUT, id=2} |
| Signature | Description |
| print (s: string): void | Writes s to STDOUT. |
| getline (): string | Reads all characters up to a newline from STDIN. |
| open (fileName: string, mode: openmode): fd | Opens the file identified by fileName. |
| close (des: fd): void | Closes a file that has already been opened. |
| eof (des: fd): bool | Returns true if the file stream is at the end. |
| read (des: fd, count: int): string | Reads count characters from a file stream. |
| write (des: fd, data: string): void | Writes data to a file stream. |
print (s: string): void
Parameters:
Notes:
getline (): string
Notes:
open (fileName: string, mode: openmode): fd
try {
def is = open ("some_file.txt", MODE_IN);
try {
(* read from the file *)
} catch (e: IOException) {
(* handle read errors *)
} finally {
close is;
}
} catch (e: IOException) {
(* handle open failure *)
}
Parameters:
Returns:
Exceptions:
Notes:
close (des: fd): void
Parameters:
Exceptions:
Notes:
eof (des: fd): bool
Parameters:
Returns:
Exceptions:
read (des: fd, count: int): string
Parameters:
Returns:
Exceptions:
Notes:
write (des: fd, data: string): void
Parameters:
Exceptions:
Notes:
| Signature | Description |
| abs (n: int): int | Absolute value. |
| promote (n: int): real | Converts an int to a real (avoid if possible). |
| gcd (a: int, b: int): int | Greatest common divisor. |
| extEuclid (a: int, b: int): int * int * int | Extended Euclidean algorithm. |
| lcm (a: int, b: int): int | Least common multiple. |
| max (a: int, b: int): int | The larger of two arguments. |
| min (a: int, b: int): int | The smaller of two arguments. |
| powMod (base: int, exponent: int, p: int): int | baseexponent (mod p) |
| invMod (a: int, m: int): int | Modular multiplicative inverse. |
| nextProbablePrime (n: int, trials: int): int | Finds the smallest prime larger than n with probability (1 - 0.25trials). |
| isProbablePrime (n: int, trials: int): int | Determines whether n is prime with probability (1 - 0.25trials). |
| div3 (dividend: int): int | Fast routine to find quotient of dividend / 3. |
| mod3 (n: int): int | Fast routine to find n (mod 3). |
| ceil (x: real): int | Finds smallest integer greater than x. |
| floor (x: real): int | Finds largest integer less than x. |
| round (x: real): int | Returns the integer closest to x. |
| pi (precision: int): real | Calculates precision digits of the number π. |
| sqrt (x: real): real | Returns the principal (nonnegative) square root of x. |
| exp (x: real): real | ex |
| log (x: real): real | ln x |
| sin (x: real): real | sin x |
| cos (x: real): real | cos x |
| tan (x: real): real | tan x |
| fpromote (n: int): float | Converts an int to a float. |
| isNaN (f: float): bool | Returns true if f is not-a-number. |
| isInf (f: float): bool | Returns true if f is either positive or negative infinity. |
| fsqrt (f: float): float | Float-valued principal square root. |
| modf (f: float): int * float | Decomposes argument into integer and fraction parts. |
abs (n: int): int
Parameters:
Returns:
promote (n: int): real
Parameters:
Returns:
Notes:
gcd (a: int, b: int): int
Parameters:
Returns:
Notes:
extEuclid (a: int, b: int): int * int * int
Parameters:
Returns:
Notes:
lcm (a: int, b: int): int
Parameters:
Returns:
Notes:
max (a: int, b: int): int
Parameters:
Returns:
max (a: int, b: int): int
Parameters:
Returns:
powMod (base: int, exponent: int, p: int): int
Parameters:
Returns:
Exceptions:
invMod (a: int, m: int): int
Parameters:
Returns:
Exceptions:
nextProbablePrime (n: int, trials: int): int
Parameters:
Returns:
Exceptions:
Notes:
isProbablePrime (n: int, trials: int): int
Parameters:
Returns:
Exceptions:
Notes:
div3 (dividend: int): int
Parameters:
Returns:
Notes:
mod3 (n: int): int
Parameters:
Returns:
Notes:
ceil (x: real): int
Parameters:
Returns:
floor (x: real): int
Parameters:
Returns:
round (x: real): int
Parameters:
Returns:
Notes:
pi (precision: int): real
Parameters:
Returns:
Exceptions:
sqrt (x: real): real
Parameters:
Returns:
Exceptions:
exp (x: real): real
Parameters:
Returns:
log (x: real): real
Parameters:
Returns:
Exceptions:
sin (x: real): real
Parameters:
Returns:
cos (x: real): real
Parameters:
Returns:
tan (x: real): real
Parameters:
Returns:
fpromote (n: int): float
Parameters:
Returns:
Exceptions:
isNaN (f: float): bool
Parameters:
Returns:
isInf (f: float): bool
Parameters:
Returns:
fsqrt (f: float): float
Parameters:
Returns:
Exceptions:
modf (f: float): int * float
Parameters:
Returns:
The definitions in this file are designed to fulfill the following purposes:
| Signature | Description |
| rand (n: int): int | Generates a random integer in the closed range [0, n * 230]. |
| randPrime (n: int): int | Generates a random prime integer guaranteed to be n bytes in size. |
rand (n: int): int
Parameters:
Returns:
Notes:
randPrime (n: int): int
Parameters:
Returns:
Notes:
| Signature | Description |
| coresAvailable (): int | Returns the number of CPU cores currently available to the runtime. |
coresAvailable (): int
Returns:
Notes:
The definitions in this file are designed to fulfill the following purposes:
| Signature | Description |
| join (delimiter: string, words: [string]): string | Concatenates the elements of words, separated by delimiter, into a single string. |
| rjust (width: int, fill: char, s: string): string | Right-justifies s in a field width characters wide. |
| ljust (width: int, fill: char, s: string): string | Left-justifies s in a field width characters wide. |
| fformat (form: string, f: float): string | Formats f according to format form. |
join (delimiter: string, words: [string]): string
Parameters:
Returns:
rjust (width: int, fill: char, s: string): string
Parameters:
Returns:
ljust (width: int, fill: char, s: string): string
Parameters:
Returns:
fformat (form: string, f: float): string
Parameters:
Returns:
Exceptions:
Notes:
This header provides an interface to a simple thread-management system.
| Data Constructor | Type Constructor | Parameterization | Description |
| BadThreadId | ThreadException | string | Thrown on invalid thread id. |
| Signature | Description |
| isRunning (threadId: string): bool | Returns true if the specified thread is running; else, returns false |
| wait (threadId: string): void | Blocks this thread until the specified thread terminates, then reclaims its resources. |
| self (): string | Returns this thread's id. |
| sleep (msec: int): void | Suspends this thread's execution for at least msec milliseconds. |
| spawn (threadId: string, arg: `a, f: `a -> void): void | Spins off a new thread named threadId beginning execution with the function call (f arg). |
| yield (): void | Abandons the remainder of this thread's timeslice. |
isRunning (threadId: string): bool
Parameters:
Returns:
Exceptions:
wait (threadId: string): void
Parameters:
Exceptions:
Notes:
self (): string
Returns:
sleep (msec: int): void
Parameters:
Exceptions:
Notes:
spawn (threadId: string, arg: `a, f: `a -> void): void
Parameters:
Notes:
yield (): void
Notes:
[ sean.p.miller at gmail dot com ]
[ last updated Saturn's Day, 7 Apr 2012 ]