Previous Up Next

Chapter 2  The Moby Basis Library

The Moby Basis library defines the standard set of types and operations that are available to all Moby programs.

2.1  Pervasive definitions

type Bool
type Char
type Rune
type Int
type Long
type Integer
type Float
type Double
type Extended

type String
type ByteArray
type FloatArray
type DoubleArray
type Vector (t)
type Array (t)
type Ref (t)
type Ptr (t)

enumtype Order {Less, Equal, Greater}
datatype Option (t) { None, Some of (t) }
datatype Either (s, t) { In1 of (s), In2 of (t) }
datatype List (t) { Nil, Cons of (t, List(t)) }
tagtype Exn
tagtype System of String extends Exn
tagtype MatchFail extends Exn
tagtype BindFail extends Exn
tagtype Domain extends Exn
tagtype DivByZero of String extends Exn
tagtype Subscript of Int extends Exn
tagtype Size of Int extends Exn
tagtype Fail of String extends Exn
val ident : [t] t -> t
val curry : [s, t, u] ((s, t) -> u) -> s -> t -> u
val uncurry : [s, t, u] (s -> t -> u) -> (s, t) -> u
val timeOfDay : () -> (Int, Int)
val itod : Int -> Double
val itof : Int -> Float
val dtoi : Double -> Int
val ftoi : Float -> Int

2.2  Overloaded identifiers and operators

2.3  The Bool module

The Bool module provides a small collection of functions on the primitive Bool type. It has the following signature:
val eq  : (Bool, Bool) -> Bool
val neq : (Bool, Bool) -> Bool
val not : Bool -> Bool
The operations have the following semantics:
eq

This function tests its arguments for equality.
It serves as an instance of the overloaded == operator and will be moved to an internal module in the future.
neq

This function tests its arguments for inequality.
It serves as an instance of the overloaded != operator and will be moved to an internal module in the future.
not

This function returns the logical negation of its argument. The operator ! is bound to this function.

2.4  The Int module

val andb : (Int, Int) -> Int
val orb  : (Int, Int) -> Int
val xor  : (Int, Int) -> Int
val rsha : (Int, Int) -> Int
val rshl : (Int, Int) -> Int
val lsh  : (Int, Int) -> Int
val not  : Int -> Int
val add  : (Int, Int) -> Int
val sub  : (Int, Int) -> Int
val mul  : (Int, Int) -> Int
val div  : (Int, Int) -> Int
val rem  : (Int, Int) -> Int
val neg  : Int -> Int
val eq   : (Int, Int) -> Bool
val neq  : (Int, Int) -> Bool
val lt   : (Int, Int) -> Bool
val lte  : (Int, Int) -> Bool
val gt   : (Int, Int) -> Bool
val gte  : (Int, Int) -> Bool
val abs  : Int -> Int
val toString : Int -> String
val toStringUnsigned : Int -> String
val fromString : String -> Option(Int)

2.5  The Long module

The Long type is not supported in this release.

2.6  The Float module

val eq  : (Float, Float) -> Bool
val neq : (Float, Float) -> Bool
val lt  : (Float, Float) -> Bool
val lte : (Float, Float) -> Bool
val gt  : (Float, Float) -> Bool
val gte : (Float, Float) -> Bool
val add : (Float, Float) -> Float
val sub : (Float, Float) -> Float
val mul : (Float, Float) -> Float
val div : (Float, Float) -> Float
val pow : (Float, Float) -> Float
val neg : Float -> Float
val abs : Float -> Float
val toString : Float -> String
val fromString : String -> Option(Float)

2.7  The Double module

val eq  : (Double, Double) -> Bool
val neq : (Double, Double) -> Bool
val lt  : (Double, Double) -> Bool
val lte : (Double, Double) -> Bool
val gt  : (Double, Double) -> Bool
val gte : (Double, Double) -> Bool
val add : (Double, Double) -> Double
val sub : (Double, Double) -> Double
val mul : (Double, Double) -> Double
val div : (Double, Double) -> Double
val pow : (Double, Double) -> Double
val neg : Double -> Double
val abs : Double -> Double
val toString : Double -> String
val fromString : String -> Option(Double)

2.8  The Extended module

2.9  The Char module

val ord : Char -> Int
val chr : Int -> Char
val eq  : (Char, Char) -> Bool
val neq : (Char, Char) -> Bool
val lt  : (Char, Char) -> Bool
val lte : (Char, Char) -> Bool
val gt  : (Char, Char) -> Bool
val gte : (Char, Char) -> Bool
val isDigit : Char -> Bool
val isLower : Char -> Bool
val isUpper : Char -> Bool
val isSpace : Char -> Bool

2.10  The String module

The String module contains functions for computing with values of the pervasive String type. It has the following signature:
val eq : (String, String) -> Bool
val neq : (String, String) -> Bool
val length : String -> Int
val sub : (String, Int) -> Char
val concat2 : (String, String) -> String
val substring : (String, Int, Int) -> String
val implode : List(Char) -> String
The operations have the following semantics:
eq

This function tests its arguments for equality.
It serves as an instance of the overloaded == operator and will be moved to an internal module in the future.
neq

This function tests its arguments for inequality.
It serves as an instance of the overloaded != operator and will be moved to an internal module in the future.
length

This function returns the length (number of characters) of its argument. The overloaded function length is also bound to this function.
sub (s, i)

This function returns the ith character of the string s. If i is less than 0 or greater or equal to the length of s, then the Subscript exception is raised with i as its argument.
This function is an instance of the overloaded subscript notation and will be moved to an internal module in the future.
concat2

This function returns a string that is the concatenation of its two arguments.
This function is an instance of the overloaded + operator and will be moved to an internal module in the future.
substring (s, i, n)

This function returns a string of length n that is the substring of s starting at position i. If i is less than 0 or i+n is greater than the length of s, then the Substring exception is raised with i as its argument.

2.11  The Vector module

val length : [t] Vector(t) -> Int
val sub : [t] (Vector(t), Int) -> t

2.12  The Array module

val array : [t] (Int, t) -> Array(t)
val length : [t] Array(t) -> Int
val fromList : [t] List(t) -> Array(t)

2.13  The ByteArray module

val array : (Int, Int) -> ByteArray
val length : ByteArray -> Int

2.14  The FloatArray module

val array : (Int, Float) -> FloatArray
val length : FloatArray -> Int

2.15  The DoubleArray module

val array : (Int, Double) -> DoubleArray
val length : DoubleArray -> Int

2.16  The Ref module

val ref : [t] t -> Ref(t)

2.17  The Option module

val map : [s, t] (s -> t) -> Option(s) -> Option(t)
val apply : [t] (t -> ()) -> Option(t) -> ()
val default : [t] (Option(t), t) -> t

2.18  The List module

val length : [t] List(t) -> Int
val apply : [t] (t -> ()) -> List(t) -> ()
val append : [t] (List(t), List(t)) -> List(t)

Previous Up Next