IvoryScript module reference

1 Introduction

The IvoryScript Module Reference provides a comprehensive list of the types, classes, instances and global names defined within each module of the language.

The reference is organized by module. Each module entry includes sections on:

  • Types: Definitions of primitive and user-defined types, including their constructors and associated usage.

  • Classes: Declarations of type classes, detailing constraints and behaviours - along with the class methods and their associated types.

  • Instances: Implementations of type classes for specific types.

  • Global names: Names in the value namespace associated with constants, variables, functions, class methods and data constructors.

2 Primitive & Built-in

Primitive and Built-in core types and functions.

2.1 Built-in type definitions

Name Module Data Constructors Description
Name Primitive # <identifier> Name
Type Primitive # <type signature> Type
Int Primitive 0 , 11 , 222... Integer
Double Primitive 3.142... Double-precision floating-point
Float Primitive By function return Single-precision floating-point
Char Primitive 'a' , 'Z' , '0' , '?'... Character
String Primitive "Example string"... String
Ptr a Primitive Ptr <expr> Pointer

2.2 Global Names

Name Module Category Type Signature Description Example
acos BuiltIn Function Double -> Double Returns the arccosine of a Double value. acos 1.0 -- returns 0.0
addDouble BuiltIn Function Double -> Double -> Double Adds two Double values. addDouble 3.0 5.0 -- returns 8.0
addFloat BuiltIn Function Float -> Float -> Float Adds two Float values. addFloat 2.5 3.5 -- returns 6.0
addInt BuiltIn Function Int -> Int -> Int Adds two Int values. addInt 4 7 -- returns 11
atan BuiltIn Function Double -> Double Returns the arctangent of a Double value. atan 1.0 -- returns 0.785398
atan2 BuiltIn Function Double -> Double -> Double Returns the arctangent of y/x, with the sign determined by the quadrant of (x, y). atan2 1.0 1.0 -- returns 0.785398
bytesToString BuiltIn Function ByteString -> String Converts a ByteString to a String. bytesToString byteArray -- converts the array to string
closeDir BuiltIn Function Dir -> Void Closes an open directory stream. N/A
compareChar BuiltIn Function Char -> Char -> Ordering Compares two characters, returning an Ordering (LT, EQ, GT). compareChar 'a' 'b' -- returns LT
compareDouble BuiltIn Function Double -> Double -> Ordering Compares two Double values, returning an Ordering (LT, EQ, GT). compareDouble 3.0 4.0 -- returns LT
compareFloat BuiltIn Function Float -> Float -> Ordering Compares two Float values, returning an Ordering (LT, EQ, GT). compareFloat 2.5 2.5 -- returns EQ
compareInt BuiltIn Function Int -> Int -> Ordering Compares two Int values, returning an Ordering (LT, EQ, GT). compareInt 7 3 -- returns GT
compareString BuiltIn Function String -> String -> Ordering Compares two strings lexicographically. compareString "apple" "banana" -- returns LT
concatByteString BuiltIn Function ByteString -> ByteString -> ByteString Concatenates two ByteString values. N/A
concatString BuiltIn Function String -> String -> String Concatenates two strings. concatString "Hello, " "world!" -- returns "Hello, world!"
dirEntryName BuiltIn Function DirEntry -> String Returns the name of a directory entry. dirEntryName(dirEntry)
divDouble BuiltIn Function Double -> Double -> Double Divides two Double values. divDouble 6.0 3.0 -- returns 2.0
divFloat BuiltIn Function Float -> Float -> Float Divides two Float values. divFloat 6.0 3.0 -- returns 2.0
divInt BuiltIn Function Int -> Int -> Int Divides two Int values. divInt 6 3 -- returns 2
eqBool BuiltIn Function Bool -> Bool -> Bool Checks equality of two Bool values. eqBool True False -- returns False
eqChar BuiltIn Function Char -> Char -> Bool Checks equality of two Char values. eqChar 'a' 'a' -- returns True
eqDouble BuiltIn Function Double -> Double -> Bool Checks equality of two Double values. eqDouble 3.0 3.0 -- returns True
eqFloat BuiltIn Function Float -> Float -> Bool Checks equality of two Float values. eqFloat 3.5 3.5 -- returns True
eqInt BuiltIn Function Int -> Int -> Bool Checks equality of two Int values. eqInt 5 5 -- returns True
eqName BuiltIn Function Name -> Name -> Bool Checks equality of two Name values. N/A
eqPtr BuiltIn Function Ptr a -> Ptr a -> Bool Checks equality of two Ptr values. N/A
eqRef BuiltIn Function Ref -> Ref -> Bool Checks equality of two Ref values. N/A
eqString BuiltIn Function String -> String -> Bool Checks equality of two String values. eqString "foo" "bar" -- returns False
eqType BuiltIn Function Type -> Type -> Bool Checks equality of two Type values. N/A
eqUTC BuiltIn Function UTC -> UTC -> Bool Checks equality of two UTC values. N/A
error BuiltIn Function String -> a Throws an error with the given message. error "An error occurred!"
exp BuiltIn Function Double -> Double Returns e raised to the power of the given Double. exp 1.0 -- returns 2.71828
firstRef BuiltIn Function Name Returns the first reference of a Name. N/A
foldRRefs BuiltIn Function Expr -> Expr -> RefList -> Any Folds over a RefList with two expressions. N/A
formatChar BuiltIn Function Char -> String -> String Formats a Char into a String with a specific format. N/A
formatDouble BuiltIn Function Double -> String -> String Formats a Double into a String with a specific format. formatDouble 3.14 "%.2f" -- returns "3.14"
formatFloat BuiltIn Function Float -> String -> String Formats a Float into a String with a specific format. formatFloat 3.14 "%.2f" -- returns "3.14"
formatInt BuiltIn Function Int -> String -> String Formats an Int into a String with a specific format. formatInt 42 "%04d" -- returns "0042"
formatString BuiltIn Function String -> String -> String Formats a String with a specific pattern. formatString "Hello" "%s" -- returns "Hello"
formatUTC BuiltIn Function UTC -> String -> String Formats a UTC time into a String with a specific format. N/A
fromDoubleFloat BuiltIn Function Float -> Float Converts a Double to a Float. N/A
fromIntDouble BuiltIn Function Int -> Double Converts an Int to a Double. fromIntDouble 42 -- returns 42.0
fromIntFloat BuiltIn Function Int -> Float Converts an Int to a Float. fromIntFloat 42 -- returns 42.0
getAtByteString BuiltIn Function ByteString -> Int -> Int Retrieves an Int from a ByteString at the specified index. N/A
getAtString BuiltIn Function String -> Int -> Char Retrieves a Char from a String at the specified index. getAtString "Hello" 1 -- returns 'e'
gtChar BuiltIn Function Char -> Char -> Bool Checks if one Char is greater than another. gtChar 'b' 'a' -- returns True
gtDouble BuiltIn Function Double -> Double -> Bool Checks if one Double is greater than another. gtDouble 5.0 3.0 -- returns True
gtEqChar BuiltIn Function Char -> Char -> Bool Checks if one Char is greater than or equal to another. gtEqChar 'a' 'a' -- returns True
gtEqDouble BuiltIn Function Double -> Double -> Bool Checks if one Double is greater than or equal to another. gtEqDouble 5.0 5.0 -- returns True
gtEqFloat BuiltIn Function Float -> Float -> Bool Checks if one Float is greater than or equal to another. gtEqFloat 5.0 5.0 -- returns True
gtEqInt BuiltIn Function Int -> Int -> Bool Checks if one Int is greater than or equal to another. gtEqInt 5 5 -- returns True
gtEqString BuiltIn Function String -> String -> Bool Checks if one String is greater than or equal to another. gtEqString "abc" "abd" -- returns False
gtEqUTC BuiltIn Function UTC -> UTC -> Bool Checks if one UTC time is greater than or equal to another. N/A
gtFloat BuiltIn Function Float -> Float -> Bool Checks if one Float is greater than another. gtFloat 5.0 3.0 -- returns True
gtInt BuiltIn Function Int -> Int -> Bool Checks if one Int is greater than another. gtInt 5 3 -- returns True
gtString BuiltIn Function String -> String -> Bool Checks if one String is greater than another. gtString "abc" "abd" -- returns False
gtUTC BuiltIn Function UTC -> UTC -> Bool Checks if one UTC time is greater than another. N/A
host BuiltIn Function Ref -> Any Returns the host associated with a reference. N/A
lengthByteString BuiltIn Function ByteString -> Int Returns the length of a ByteString. N/A
lengthString BuiltIn Function String -> Int Returns the length of a string. lengthString "Hello" -- returns 5
log BuiltIn Function Double -> Double Returns the natural logarithm of a Double. log 2.718 -- returns 1
log10 Double -> Double Returns the base-10 logarithm of a Double. log10 100.0 -- returns 2
lShiftBits32 BuiltIn Function Bits32 -> Bits32 -> Bits32 Performs a left bitwise shift on a 32-bit integer. lShiftBits32 4 1 -- returns 8
mapAnyPtr BuiltIn Function BuiltIn Any -> Env -> Ptr a Maps an environment onto a pointer structure. N/A
mapName BuiltIn Function BuiltIn Name -> Env -> Name Maps an environment onto a name structure. N/A
mapString BuiltIn Function String -> Env -> String Maps an environment onto a string structure. N/A
modInt BuiltIn Function Int -> Int -> Int Returns the modulus of two integers. modInt 10 3 -- returns 1
mulDouble BuiltIn Function Double -> Double -> Double Multiplies two double precision numbers. mulDouble 2.0 3.0 -- returns 6.0
mulFloat BuiltIn Function Float -> Float -> Float Multiplies two floating point numbers. mulFloat 2.0 3.0 -- returns 6.0
mulInt BuiltIn Function Int -> Int -> Int Multiplies two integers. mulInt 2 3 -- returns 6
mutableString BuiltIn Function Int -> String Creates a mutable string of a given length. N/A
nEqBool BuiltIn Function Bool -> Bool -> Bool Checks if two boolean values are not equal. nEqBool True False -- returns True
nEqChar BuiltIn Function Char -> Char -> Bool Checks if two characters are not equal. nEqChar 'a' 'b' -- returns True
nEqDouble BuiltIn Function Double -> Double -> Bool Checks if two double precision numbers are not equal. nEqDouble 1.0 2.0 -- returns True
nEqFloat BuiltIn Function Float -> Float -> Bool Checks if two floating point numbers are not equal. nEqFloat 1.0 2.0 -- returns True
nEqInt BuiltIn Function Int -> Int -> Bool Checks if two integers are not equal. nEqInt 1 2 -- returns True
nEqRef BuiltIn Function Ref -> Ref -> Bool Checks if two references are not equal. N/A
nEqString BuiltIn Function String -> String -> Bool Checks if two strings are not equal. nEqString "abc" "def" -- returns True
nEqUTC BuiltIn Function UTC -> UTC -> Bool Checks if two UTC times are not equal. N/A
negDouble BuiltIn Function Double -> Double Returns the negation of a double precision number. negDouble 3.0 -- returns -3.0
negInt BuiltIn Function Int -> Int Negates an integer value. negInt 5 -- returns -5
negateFloat BuiltIn Function Float -> Float Returns the negation of a floating point number. negateFloat 3.14 -- returns -3.14
nextDirEntry BuiltIn Function Dir -> Maybe DirEntry Retrieves the next directory entry, if available. N/A
notBits32 BuiltIn Function Bits32 -> Bits32 Returns the bitwise negation of a 32-bit value. notBits32 0xFF -- returns 0xFFFFFF00
openDir BuiltIn Function String -> Maybe Dir Opens a directory for reading entries. openDir "/home/user" -- returns Maybe Dir
orBits32 BuiltIn Function Bits32 -> Bits32 -> Bits32 Performs bitwise OR on two 32-bit values. orBits32 0x1F 0xF0 -- returns 0xFF
pow BuiltIn Function Double -> Double -> Double Raises one double to the power of another. pow 2.0 3.0 -- returns 8.0
rShiftBits32 BuiltIn Function Bits32 -> Bits32 -> Bits32 Performs a right shift on a 32-bit value. rShiftBits32 0xFF 2 -- returns 0x3F
radians BuiltIn Function Double -> Double Converts degrees to radians. radians 180 -- returns 3.14159
receiveScript BuiltIn Function RefList -> Void Receives a script to process. N/A
reverseString BuiltIn Function String -> String Reverses the characters in a string. reverseString "hello" -- returns "olleh"
selectADS BuiltIn ADS -> Name -> Any Selects an entry from an ADS by name. N/A
setEnv BuiltIn Function Env -> Void Sets the environment for further operations. N/A
showAny BuiltIn Function Any -> Void Displays any value to the standard output. N/A
showBool BuiltIn Function Bool -> Void Displays a boolean value. showBool True -- prints 'True'
showByteString BuiltIn Function ByteString -> Void Displays a ByteString. N/A
showChar BuiltIn Function Char -> Void Displays a character value. showChar 'a' -- prints 'a'
showDouble BuiltIn Function Double -> Void Displays a double-precision floating-point number. showDouble 3.14159 -- prints '3.14159'
showFloat BuiltIn Function Float -> Void Displays a single-precision floating-point number. showFloat 2.718 -- prints '2.718'
showInt BuiltIn Function Int -> Void Displays an integer value. showInt 42 -- prints '42'
showName BuiltIn Function Name -> Void Displays a name value. N/A
showOrdering BuiltIn Function Ordering -> Void Displays an ordering value. N/A
showString BuiltIn Function String -> Void Displays a string value. showString "hello" -- prints 'hello'
showType BuiltIn Function Type -> Void Displays a type value. N/A
showUTC BuiltIn Function UTC -> Void Displays a UTC value. N/A
showWhen BuiltIn Function When -> Void Displays a 'When' event phase value. N/A
sin BuiltIn Function Double -> Double Calculates the sine of a given angle in radians. sin 1.5708 -- returns 1.0
sinh BuiltIn Function Double -> Double Calculates the hyperbolic sine of a number. N/A
sqrt BuiltIn Function Double -> Double Calculates the square root of a number. sqrt 4.0 -- returns 2.0
subDouble BuiltIn Function Double -> Double -> Double Subtracts two double-precision floating-point numbers. subDouble 5.5 2.5 -- returns 3.0
subFloat BuiltIn Function Float -> Float -> Float Subtracts two single-precision floating-point numbers. subFloat 5.5 2.5 -- returns 3.0
subInt BuiltIn Function Int -> Int -> Int Subtracts two integers. subInt 5 2 -- returns 3
substring BuiltIn Function String -> Int -> Int -> String Extracts a substring from a given string. substring "hello" 1 3 -- returns "ell"
tan BuiltIn Function Double -> Double Calculates the tangent of a given angle in radians. tan 0.7854 -- returns 1.0
tanh BuiltIn Function Double -> Double Calculates the hyperbolic tangent of a number. N/A
time BuiltIn Function UTC Returns the current UTC time. N/A
timeDiff BuiltIn Function UTC -> UTC -> Int Calculates the difference between two UTC times in seconds. N/A
trace BuiltIn Function String -> Void Prints a debug trace message to standard output. trace "Debug message"

3 Prelude

The Prelude module extends the primitive and built-in core functionality.

3.1 Type definitions

Type Module Data Constructor(s) Description
Bool Prelude False, True Boolean values representing truth states
Maybe a Prelude Nothing, Just a Represents an optional value; either Nothing or Just a value
Ordering Prelude LT, EQ, GT Represents comparison results (less than, equal, greater than)
Env Prelude Env Int Represents an environment, used for mapping contexts
Ptr a Prelude Null, Ptr a Pointer type, nullable, for referencing data
Array a Prelude Array [a] Type for arrays, representing a list of elements of type a

3.2 Class Definitions

Class Module Methods Description
Env a Prelude needsEnv, mapToEnv, copyToPtr Defines environment-dependent behavior, supporting mapping and copying objects to different environments
EnvIndependent a Prelude inherits Env Specialization of Env for environment-independent objects
EnvDependent a Prelude inherits Env Specialization of Env for objects dependent on environment
Eval a, b Prelude eval Provides a mechanism to evaluate expressions of type a to type b
Cast a, b Prelude cast Defines casting behavior between types a and b
StrictCast a, b Prelude strictCast Enforces strict casting between types
Mark_GC a Prelude mark_GC Marks objects for garbage collection
Eq a Prelude =, ¬= Defines equality and inequality operations
Ord a Prelude <, <=, >, >=, compare, max Extends Eq with ordering operations and comparison
Bitwise a Prelude <<, >>, #&, #^, #|, Defines bitwise operations
Num a Prelude zero, succ, pred, +, -, *, mod, plus, negate, fromInt Defines numeric operations and constants for numbers
FractionalNum a Prelude / Extends Num to support division
Select a, b Prelude . Allows selection of a named field from a type
Seq a Prelude length, tail, take, ++ Defines sequential operations such as length, tail, take, and concatenation
ReverseableSeq a Prelude reverse, reverse_ns Provides reverse operations for sequences
IndexableSeq a, b Prelude getAt, putAt, head Supports indexed access and modification for sequences
Fetch a Prelude fetch Fetches an expression’s evaluated value
Show a Prelude format, show, showWithNewline Defines formatting and display operations

3.3 Instances

Class Module Type(s) Qualifier(s) Method(s) Description
Env Prelude Env - - Defines Env as an environment-dependent type
Mark_GC Prelude Env - mark_GC Enables garbage collection for Env objects
Eq Prelude Env - =, ¬= Defines equality operations for Env type
Show Prelude Exp Void - show, showWithNewline Provides display capabilities for Exp Void
Env Prelude (-> b) - needsEnv, mapToEnv Defines environment handling for thunks of type (-> b)
Env Prelude (b -> c) - needsEnv, mapToEnv Defines environment handling for function types (b -> c)
Mark_GC Prelude (b -> c) - mark_GC Marks function types (b -> c) for garbage collection
Show Prelude (b -> c) - show Display function for types (b -> c)
Env Prelude Exp b - needsEnv, mapToEnv Provides environment handling for expressions of type Exp b
Mark_GC Prelude Exp b - mark_GC Marks expressions of type Exp b for garbage collection
Eval Prelude Exp b, b | !b eval Provides evaluation for expressions of type Exp b to b
Cast Prelude Exp c, b - cast Defines casting from expressions of type Exp c to b
Cast Prelude Exp b, b - cast A cast from Exp b to b (simple reduction)
Env Prelude Env - - Defines Env as an environment-dependent type
Mark_GC Prelude Env - mark_GC Enables garbage collection for Env objects
Eq Prelude Env - =, ¬= Defines equality operations for Env type
Show Prelude Exp Void - show, showWithNewline Provides display capabilities for Exp Void
Env Prelude (-> b) - needsEnv, mapToEnv Defines environment handling for thunks of type (-> b)
Env Prelude (b -> c) - needsEnv, mapToEnv Defines environment handling for function types (b -> c)
Mark_GC Prelude (b -> c) - mark_GC Marks function types (b -> c) for garbage collection
Show Prelude (b -> c) - show Display function for types (b -> c)
Env Prelude Exp b - needsEnv, mapToEnv Provides environment handling for expressions of type Exp b
Mark_GC Prelude Exp b - mark_GC Marks expressions of type Exp b for garbage collection
Eval Prelude Exp b, b | !b eval Provides evaluation for expressions of type Exp b to b
Cast Prelude Exp c, b - cast Defines casting from expressions of type Exp c to b
FractionalNum Prelude Double - / Defines division for Double type
Eq Prelude Double - =, ¬= Provides equality operations for Double type
Ord Prelude Double - <, <=, >, >=, compare Defines ordering for Double values
Show Prelude Double - show, format Provides display and formatting for Double type
Env Prelude Char - needsEnv, mapToEnv Environment mapping for Char type
Eq Prelude Char - =, ¬= Defines equality operations for Char type
Ord Prelude Char - <, <=, >, >=, compare Provides ordering for Char values
Show Prelude Char - show, format Provides display and formatting for Char type
Env Prelude Bool - needsEnv, mapToEnv Handles environment mapping for Bool type
Eq Prelude Bool - =, ¬= Equality operations for Bool values
Show Prelude Bool - show Display function for Bool type
Env Prelude Ptr b | b ¬= Array c needsEnv, mapToEnv Environment mapping for Ptr b type
Eq Prelude Ptr b - = Equality operations for Ptr b type
Show Prelude Ptr b | b ¬= Array c show Display function for Ptr b type
Env Prelude (b, c) - needsEnv, mapToEnv Environment mapping for pair type (b, c)
Eq Prelude (b, c) - = Equality operations for pair type (b, c)
Show Prelude (b, c) - show Display function for pair type (b, c)
Env Prelude (b, c, d) - needsEnv, mapToEnv Environment mapping for triple type (b, c, d)
Eq Prelude (b, c, d) - = Equality operations for triple type (b, c, d)
Show Prelude (b, c, d) - show Display function for triple type (b, c, d)
Show Prelude Ordering - show Display function for Ordering type
Show Prelude When - show Display function for When type
Show Prelude Maybe b - show Display function for Maybe type, handles Just and Nothing cases

3.4 Global names

Name Module Category Type Signature Description Example
(+) Prelude Class Method Num a => a -> a -> a Addition (+) 5 3 gives 8
(-) Prelude Class Method Num a => a -> a -> a Subtraction (-) 5 3 gives 2
(*) Prelude Class Method Num a => a -> a -> a Multiplication (*) 5 3 gives 15
(=) Prelude Class Method Eq a => a -> a -> Bool Equality comparison. (=) 5 5 gives True
(¬=) Prelude Class Method Eq a => a -> a -> Bool Inequality comparison. (¬=) 5 3 gives True
(<=) Prelude Class Method Ord a => a -> a -> Bool Less-than-or-equal comparison. (<) 5 8 gives True
(<) Prelude Class Method Ord a => a -> a -> Bool Less-than comparison. (<)5 8 gives True
(>=) Prelude Class Method Ord a => a -> a -> Bool Greater-than-or-equal comparison. (>=) 5 3 gives True
(>) Prelude Class Method Ord a => a -> a -> Bool Greater-than comparison. (>)5 3 gives True
(<<) Prelude Class Method Bitwise a => a -> a -> a Left bitwise shift. (<<) x 2 shifts bits of x two places left.
(>>) Prelude Class Method Bitwise a => a -> a -> a Right bitwise shift. (>>) x 2 shifts bits of x two places right.
abs Prelude Class Method Num a => a -> a Absolute value of a number. abs (-5) gives 5
allocPtrArray Prelude Function Int -> Ptr (Array a) Allocates a pointer array with the specified size. allocPtrArray 5
andBits32 Prelude Function Bits32 -> Bits32 -> Bits32 Bitwise AND operation on Bits32. andBits32 x y
assign Prelude Function a -> Ptr a -> Void Assigns a value to a pointer. assign 5 ptr
concat Prelude Function Foldable t => t [a] -> [a] Concatenates all lists within a structure. concat [[1, 2], [3, 4]] gives [1, 2, 3, 4]
copyClosure Prelude Function a -> Env -> a Copies a closure to a specified environment. copyClosure myClosure newEnv
dePtr Prelude Function Ptr a -> a Dereferences a pointer. dePtr ptr
div Prelude Class Method Integral a => a -> a -> a Integer division operator. 7 `div` 2 gives 3
id Prelude Function a -> a Identity function that returns its argument. id 42 gives 42
isNothing Prelude Function Maybe a -> Bool Checks if a Maybe value is Nothing. isNothing Nothing gives True
tail Prelude Class Method Seq a => a -> a Returns a sequence without its first element. tail [1, 2, 3] gives [2, 3]
take Prelude Function Int -> [a] -> [a] Returns the first n elements of a list. take 2 [1, 2, 3] gives [1, 2]

4 Extended tuples

The Tuple_4_10module provides environment management and display (show) functionality for tuples from quadruples (4 elements) to decuples (10 elements).

4.1 Instance Definitions

Class Type(s) Module Method(s)
Env (b, c, d, e) Tuple_4_10 needsEnv, mapToEnv
Show (b, c, d, e) Tuple_4_10 show
Env (b, c, d, e, f) Tuple_4_10 needsEnv, mapToEnv
Show (b, c, d, e, f) Tuple_4_10 show
Env (b, c, d, e, f, g) Tuple_4_10 needsEnv, mapToEnv
Show (b, c, d, e, f, g) Tuple_4_10 show
Env (b, c, d, e, f, g, h) Tuple_4_10 needsEnv, mapToEnv
Show (b, c, d, e, f, g, h) Tuple_4_10 show
Env (b, c, d, e, f, g, h, i) Tuple_4_10 needsEnv, mapToEnv
Show (b, c, d, e, f, g, h, i) Tuple_4_10 show
Env (b, c, d, e, f, g, h, i, j) Tuple_4_10 needsEnv, mapToEnv
Show (b, c, d, e, f, g, h, i, j) Tuple_4_10 show
Env (b, c, d, e, f, g, h, i, j, k) Tuple_4_10 needsEnv, mapToEnv
Show (b, c, d, e, f, g, h, i, j, k) Tuple_4_10 show

5 Any

The Any module provides a generic type implementation that allows handling of values of any type. It includes constructors and methods for working with the Any type, along with conversions between other types and Any.

5.1 Type Definitions

Name Module Data Constructors Description
Any Any Any a Generic type that can hold a value of any type.
AnyRepr Any ImmediateAny a, IndirectAny a Representation of `Any` values either directly or through pointers.

5.2 Function Definitions

Name Module Category Type Signature Description
Any Any Data constructor a -> (Type, Ptr a) Constructs an `Any` from a value, associating it with its type.
typeOfAny Any Variable Any -> Type Returns the type of the value stored in an `Any`.
mapToEnv Any Class method Env Any => Any -> Env -> Any Maps an `Any` value to a new environment.

5.3 Instance Definitions

Class Type(s) Module Qualifier(s) Method(s)
StrictCast Any, c Any c ¬= Void strictCast
StrictCast c, Any Any !c, c ¬= Void, c ¬= Any strictCast
Env Any Any needsEnv, mapToEnv
Show Any Any show

6 Binding

The Binding module provides an implementation for bindings between two types.

6.1 Type definitions

Name Module Data Constructors Description
Binding a b Binding Bind a b Represents a binding between two values.

6.2 Global names

Name Module Category Type Signature Description
Bind Binding Data constructor a -> b -> (a, b) Constructs a binding between two values.

6.3 Class definitions

Name Module Type Signature Description
BindingSet Binding addBinding :: a -> b -> c -> Void Adds a binding to a set.
hasBinding :: a -> b -> Bool Checks if a binding exists in a set.
removeBinding :: a -> b -> Void Removes a binding from a set.

6.4 Instance definitions

Class Type(s) Module Method(s)
Env Binding b c Binding needsEnv, mapToEnv
Show Binding b c Binding show
StrictCast Binding Name c, Binding Name Any Binding strictCast

7 List

The List module provides implementations for working with lists, including functions for list manipulation, environment management, and display. It supports both strict and non-strict functions on list elements.

7.1 Function Definitions

Name Module Category Type Signature Description
concatList List Variable [a] -> Exp[a] -> Exp [a] Concatenates two lists.
concatListStrict List Variable [a] -> [a] -> [a] Concatenates two lists (strict).
cycle List Variable [a] -> Exp [a] Creates an infinite list by repeating a list.
drop List Variable Int -> [a] -> [a] Drops the first `n` elements of a list (strict).
hd List Variable [a] -> a Returns the head of a list (strict).
hd_ns List Variable Exp [a] -> a Returns the head of a list (non-strict).
lengthList List Variable [a] -> Int Returns the length of a list (strict).
lengthList_poly List Variable b -> Int Returns the length of a polymorphic list.
listFrom List Variable a -> a -> Exp [a] Creates a list with values starting from `s` with step `step`.
listFromTo List Variable a -> a -> a -> Exp [a] Creates a list from `s` to `e` with step `step`.
listHasItem List Variable (a -> a -> Bool) -> a -> [a] -> Bool Checks if a list contains an item according to a predicate.
merge List Variable [a] -> [a] -> [a] Merges two ordered lists into one ordered list.
noDupsInList List Variable (a -> a -> Bool) -> [a] -> Bool Checks if a list contains no duplicate items.
Nil List Data constructor Ptr Void Represents an empty list.
repeat List Variable a -> Exp [a] Creates an infinite list with the same value repeated.
replicate List Variable a -> Int -> Exp [a] Replicates a value `n` times in a list.
reverseList List Variable [a] -> Exp [a] Reverses a list (strict).
reverseUnmapped List Variable [a] -> Exp [a] Reverses a list (unmapped).
takeList List Variable Int -> [a] -> Exp [a] Takes the first `n` elements of a list (strict).
takeList_ns List Variable Int -> Exp [a] -> Exp [a] Takes the first `n` elements of a list (non-strict).
tl List Variable b -> Exp [a] Returns the tail of a list (strict).
uniqueList List Variable (a -> a -> Bool) -> [a] -> [a] Returns a list with unique elements (removes duplicates).

7.2 Instance Definitions

Class Type(s) Module Method(s)
Env [b] List needsEnv, mapToEnv
Show [b] List show
Seq [c] List length, tail, take, (++)
ReverseableSeq [c] List reverse_ns
IndexableSeq [c], c List head

8 List functions

The ListFunction module provides a set of operations on lists that involve functions, including filtering, folding and mapping.

8.1 Function Definitions

Name Module Category Type Signature Description Example
filter ListFunction Variable (a -> Bool) -> [a] -> Exp [a] Filters elements of a list based on a predicate. filter (> 2) [1, 2, 3, 4] → [3, 4]
foldl ListFunction Variable (b -> a -> b) -> b -> [a] -> b Left-associative fold of a list using a function. foldl (+) 0 [1, 2, 3, 4] → 10
foldr ListFunction Variable (a -> b -> b) -> b -> [a] -> b Right-associative fold of a list using a function. foldr (:) [] [1, 2, 3] → [1, 2, 3]
groupBy ListFunction Variable (a -> a -> Bool) -> [a] -> [[a]] Groups elements of a list according to a predicate. groupBy (==) [1, 1, 2, 3, 3, 4] → [[1,1], [2], [3,3], [4]]
iterate ListFunction Variable (a -> a) -> a -> Exp [a] Produces an infinite list by applying a function iteratively. take 5 (iterate (+1) 0) → [0, 1, 2, 3, 4]
mapf ListFunction Variable (a -> b) -> [a] -> Exp [b] Applies a function to all elements of a list. mapf (*2) [1, 2, 3] → [2, 4, 6]
mergeSort ListFunction Variable [a] -> [a] Sorts a list using merge sort. mergeSort [3, 1, 4, 2] → [1, 2, 3, 4]
span ListFunction Variable (a -> Bool) -> [a] -> ([a], [a]) Splits a list into a prefix of elements satisfying a predicate and the remainder. span (<) [1="", 2="", 3="", 4=""] →="" ([1="", 2=""], [3="", 4=""])

9 Strings and character lists

The StringCharList module provides basic string and character list functions, including conversions between them.

9.1 Function Definitions

Name Module Category Type Signature Description
chars StringList Variable String -> Exp [Char] Converts a string into a list of characters.
quotedChars StringList Variable [Char] -> [String] Converts a list of characters into a list of quoted strings.
string StringList Variable [Char] -> String Converts a list of characters into a string.

9.2 Function Descriptions

chars: Converts a string into an Exp [Char], which is a list of characters wrapped in an expression for lazy evaluation.

chars "Hello" → ['H', 'e', 'l', 'l', 'o']

quotedChars: Converts a list of characters into a list of quoted strings, wrapping each character in single quotes.

quotedChars ['H', 'e', 'l', 'l', 'o'] → ["'H'", "'e'", "'l'", "'l'", "'o'"]

string: Converts a list of characters back into a String.

string ['H', 'e', 'l', 'l', 'o'] → "Hello"

9.3 Instance Definitions

Class Type(s) Module Method(s)
StrictCast [Char], String StringList strictCast
StrictCast String, [Char] StringList strictCast

10 Tree

The Tree module defines a binary tree data type and provides functions for manipulating and displaying trees. Operations include calculating the depth of a tree, finding the maximum value, and summing all elements.

10.1 Type Definitions

Name Module Data Constructors Description
Tree Tree Empty, Leaf a, Branch (Exp (Tree a)) (Exp (Tree a)) A binary tree that can either be empty, contain a value (leaf), or have two subtrees (branch).

10.2 Global Names

Name Module Category Type Signature Description Example
Branch Tree Data Constructor Exp (Tree a) -> Exp (Tree a) -> Ptr (Exp (Tree a), Exp (Tree a)) Constructs a branch node with left and right subtrees. Branch (Leaf 5) (Leaf 10) creates a tree with two leaves.
depthTree Tree Variable Tree a -> Int Returns the depth of a tree. depthTree (Branch (Leaf 5) (Empty)) → 1
Empty Tree Data Constructor Tree a Represents an empty tree. Empty creates an empty tree.
Leaf Tree Data Constructor a -> Ptr a Constructs a leaf node in a tree. Leaf 5 creates a leaf node containing the value 5.
maxTree Tree Variable Tree a -> Maybe a Finds the maximum value in the tree. maxTree (Branch (Leaf 5) (Leaf 10)) → Just 10
sumTree Tree Variable Tree a -> a Sums all the values in the tree. sumTree (Branch (Leaf 5) (Leaf 10)) → 15

10.3 Instance Definitions

Class Type(s) Module Method(s)
Env Tree b Tree needsEnv, mapToEnv
Show Tree b Tree show

11 Array

The Array module defines type methods for the Array type in IvoryScript. However, direct arrays are not currently supported in IvoryScript, and only the supertype Ptr (Array a) is supported. All dynamic types must override the type methods.

11.1 Instance Definitions

Class Type(s) Module Method(s)
Env Array b Array needsEnv, mapToEnv
Show Array b Array show

12 Vector

The Vector module defines the Vector type, which is a dynamic-length array optimized for efficiency compared to lists. It supports common operations such as getting and setting values, resizing, and searching for elements.

12.1 Type Definitions

Name Module Data Constructors Description
Vector Vector Vector [a] Int A dynamic-length array supporting various operations for efficiency.

12.2 Global Names

Name Module Category Type Signature Description Example
findVectorIndex Vector Variable Vector a -> a -> Int Finds the lowest index matching a given value in the vector. findVectorIndex vec 5 finds the index of 5 in the vector.
getAtVector Vector Variable Vector a -> Int -> a Retrieves the element at a given index in the vector. getAtVector vec 0 retrieves the first element.
lengthVector Vector Variable Vector a -> Int Returns the length of the vector. lengthVector vec returns the length of vec.
putAtVector Vector Variable Vector a -> Int -> a -> Void Updates the element at a given index in the vector. putAtVector vec 0 10 updates the first element to 10.
resizeVector Vector Variable Ptr (Vector a) -> Int -> Void Resizes the vector to a new length. resizeVector vec 10 resizes the vector to 10 elements.
Vector Vector Data Constructor [a] -> Int -> (Int, Int, Ptr (Array(Ptr (Array a)))) Constructs a vector from a list of elements and slice size. Vector [1, 2, 3] 2 creates a vector with 2 elements per slice.

12.3 Instance Definitions

Class Type(s) Module Method(s)
Env Vector b Vector needsEnv, mapToEnv
Seq Vector b Vector length
IndexableSeq Vector b, b Vector getAt, putAt
Show Vector b Vector show

13 Hahs table

The HashTable module implements a conventional data type to map keys to values using an array of slots, each comprising a chain of nodes. It supports basic operations such as adding, retrieving, and removing key-value pairs where the keys are of a custom type and the values can be any type.

13.1 Type Definitions

Name Module Data Constructors Description
HashTable HashTable HashTable Int A hash table type mapping keys to values using slot chains.
HashTableEntry HashTable HashTableEntry (Ptr (HashTableEntry keyType valType)) keyType valType Represents a node in the hash table chain. Each node contains a key, value, and pointer to the next node.

13.2 Global Names

Name Module Category Type Signature Description Example
findInHashTableSlot HashTable Variable Ptr (HashTableEntry keyType valType) -> keyType -> Ptr (HashTableEntry keyType valType) Searches for a node with the specified key in the slot chain. findInHashTableSlot slots key searches the slot for a key.
HashTable HashTable Data Constructor Int -> (Int, Ptr (Array(Ptr (HashTableEntry keyType valType)))) Constructs a hash table with a specified number of slots. HashTable 10 creates a hash table with 10 slots.
HashTableEntry HashTable Data Constructor Ptr (HashTableEntry keyType valType) -> keyType -> valType -> (Ptr (HashTableEntry keyType valType), keyType, valType) Constructs a hash table entry (node) containing a key and value. HashTableEntry next key value creates a node in the hash table.
hashTableAdd HashTable Variable (HashTable keyType valType) -> Int -> keyType -> valType -> Void Adds a new key-value pair to the hash table. hashTableAdd ht 123 key value adds a key-value pair.
hashTableGet HashTable Variable (HashTable keyType valType) -> Int -> keyType -> Maybe valType Retrieves the value associated with a given key. hashTableGet ht 123 key retrieves the value for key.
hashTableRemove HashTable Variable (HashTable keyType valType) -> Int -> keyType -> Void Removes a key-value pair from the hash table. hashTableRemove ht 123 key removes the key from the table.
setHashTableEntryNext HashTable Variable Ptr (HashTableEntry keyType valType) -> Ptr (HashTableEntry keyType valType) -> Void Updates the next pointer for a node in the chain. setHashTableEntryNext next nodePtr updates the chain link.

13.3 Instance Definitions

Class Type(s) Module Method(s)
Env HashTableEntry keyType valType HashTable needsEnv, mapToEnv
Show HashTableEntry keyType valType HashTable show
Env HashTable keyType valType HashTable needsEnv, mapToEnv
Show HashTable keyType valType HashTable show

14 Name/Any map

The NameAnyMap module implements a map from names to values of type Any using a hash table. This module supports basic operations for binding, retrieving, and removing key-value pairs where the keys are of type Name and the values are of type Any.

14.1 Type Definitions

Name Module Data Constructors Description
NameAnyMap NameAnyMap NameAnyMap Int A hash table mapping Name to values of type Any.

14.2 Global Names

Name Module Category Type Signature Description Example
NameAnyMap NameAnyMap Data Constructor Int -> HashTable Name Any Constructs a name-to-Any mapping using a hash table with the specified number of slots. NameAnyMap 10 creates a map with 10 slots.
addBinding NameAnyMap Variable NameAnyMap -> Name -> Any -> Void Adds a name-value binding to the map. addBinding map name value adds the binding to the map.
removeBinding NameAnyMap Variable NameAnyMap -> Name -> Void Removes the binding for the given name from the map. removeBinding map name removes the binding for name.
mapToEnv NameAnyMap Variable NameAnyMap -> Env -> NameAnyMap Maps the NameAnyMap to the given environment (to be defined). TBD
needsEnv NameAnyMap Variable NameAnyMap -> Bool Checks if the map requires an environment (to be defined). TBD
show NameAnyMap Variable NameAnyMap -> Void Displays the contents of the map. show map displays the hash table structure.
(.) NameAnyMap Class Method NameAnyMap -> Name -> Any Retrieves the value associated with the given name from the map. map.name returns the value bound to name.

14.3 Instance Definitions

Class Type(s) Module Method(s)
BindingSet NameAnyMap, Name, Any NameAnyMap addBinding, removeBinding
Env NameAnyMap NameAnyMap needsEnv, mapToEnv
Show NameAnyMap NameAnyMap show
Select NameAnyMap, Any NameAnyMap (.)

17 Mathematical constants

The MathConst module provides definitions for common mathematical constants such as e and pi, along with other important constants like the golden ratio, square root of 2, and natural logarithms.

17.1 Global Names

Name Module Category Type Signature Description Example
e MathConst Variable Double Represents the mathematical constant e (Euler's number). e = 2.71828182845904523536
pi MathConst Variable Double Represents the mathematical constant pi (ratio of a circle's circumference to its diameter). pi = 3.14159265358979323846
phi MathConst Variable Double Represents the golden ratio, a mathematical constant with many applications in geometry and art. phi = 1.61803398874989484820
sqrt2 MathConst Variable Double Represents the square root of 2, commonly used in geometry. sqrt2 = 1.41421356237309504880
ln2 MathConst Variable Double Represents the natural logarithm of 2, important in logarithmic calculations. ln2 = 0.69314718055994530942
ln10 MathConst Variable Double Represents the natural logarithm of 10, useful in logarithmic base conversions. ln10 = 2.30258509299404568402

18 Arithmetic functions

The Arith module implements common arithmetic functions such as factorial, greatest common divisor (gcd), least common multiple (lcm), and Fibonacci numbers etc.

18.1 Global Names

Name Module Category Type Signature Description Example
fact Arith Variable Int -> Int Computes the factorial of a number using tail recursion. fact 5 computes 120.
fibonacci Arith Variable Int -> Int Computes the nth Fibonacci number. fibonacci 10 computes 55.
gcd Arith Variable Int -> Int -> Int Computes the greatest common divisor of two numbers using the Euclidean algorithm. gcd 54 24 computes 6.
lcm Arith Variable Int -> Int -> Int Computes the least common multiple of two numbers. lcm 54 24 computes 216.

19 Numeric sequences

The NumSeq module provides common arithmetic functions operating on lists of numeric sequences.

19.1 Class Definitions

Class Name Type Variables Methods
NumSeq a, b
Name Type Signature Defined
mean a -> b No
sum a -> b No

19.2 Class Definitions

Name Type Signatures Description
NumSeq a, b addBinding :: a -> b -> c -> Void Adds a binding to a set.
hasBinding :: a -> b -> Bool Checks if a binding exists in a set.
removeBinding :: a -> b -> Void Removes a binding from a set.

19.3 Global Names

Name Module Category Type Signature Description Example
median NumSeq Function [a] -> b Returns the median of a list of numbers. median [1, 2, 3, 4, 5] computes 3.
sum NumSeq Class method a -> b Returns the sum of a list of numbers. sum [1, 2, 3] computes 6.
mean NumSeq Class method a -> b Returns the mean of a list of numbers. mean [1, 2, 3] computes 2.

19.4 Instances

Class Type(s) Qualifier(s) Method(s) Description
NumSeq [Int], Int sum sum of a list of integers.
NumSeq [Double], Double sum, mean sum and mean of a list of double precision numbers.

20 Integer sequences

The IntSeq module implements common integer sequences such as factorials, Fibonacci numbers and prime numbers.

20.1 Global Names

Name Module Category Type Signature Description Example
factorials IntSeq Variable Exp [Int] Returns an unevaluated infinite sequence of factorial numbers. take 5 (!factorials) generates [1, 1, 2, 6, 24].
fibonaccis IntSeq Variable Exp [Int] Returns an unevaluated infinite sequence of Fibonacci numbers. take 5 (!fibonaccis) generates the sequence [0, 1, 1, 2, 3].
primes IntSeq Variable Exp [Int] Returns an unevaluated infinite sequence of prime numbers using a sieve method. take 5 (!primes) generates the sequence [2, 3, 5, 7, 11].

21 Dir

The Dir module provides file system directory functions. It uses the built-in data types Dir and DirEnt and the built-in function nextDirEntry.

21.1 Global Names

Name Module Category Type Signature Description Example
dir Dir Function String -> Exp [String] Returns an unevaluated list of file names in the specified directory. dir "/home/user"

21.2 Instances

Class Type(s) Qualifier(s) Method(s) Description
Env DirEntry Identity instance - n.b. DirEnt should not be persistent.
Env Dir Identity instance - n.b. Dir should not be persistent.