- Tests
- Global scope builtins
- Unit
unit - Boolean
bool - Integer
int - Float
float - Tuple
- String
string - List
'a list - Array
'a array - Function
<fun> - Useful implementations
- ( * )
- ( ** )
- ( *.)
- (!=)
- (&&)
- (+)
- (+.)
- (-)
- (-.)
- (/)
- (/.)
- (::)
- (<)
- (<=)
- (<>)
- (=)
- (==)
- (>)
- (>=)
- (@)
- (^)
- (mod)
- (not)
- (||)
- Array.init
- Array.length
- Array.make
- Array.make_matrix
- Function definition
- Function with pattern matching
- List.fold_left
- List.fold_right
- List.hd
- List.iter
- List.length
- List.map
- List.mem
- List.nth
- List.rev
- List.tl
- Recursive function
- String.[]
- String.get
- String.init
- String.length
- String.make
- String.sub
- abs
- acos
- array_of_string
- asin
- atan
- char_of_string
- compare
- cos
- exp
- float_of_int
- float_of_string
- fst
- gcd
- ignore
- int_of_float
- int_of_string
- log
- log10
- max
- min
- print_float
- print_int
- print_newline
- print_string
- sin
- snd
- sqrt
- string_of_array
- string_of_char
- string_of_float
- string_of_int
- tan
All of these test operators are generally O(1) in Space and Time complexity
Complexity may differ depending on the provided type
'a
(=) : 'a -> 'a -> boolValue equality
(<>) : 'a -> 'a -> boolValue inequality
(==) : 'a -> 'a -> boolIdentity equality
(!=) : 'a -> 'a -> boolIdentity inequality
(<) : 'a -> 'a -> boolStrictly smaller comparator
(>) : 'a -> 'a -> boolStrictly greater comparator
(<=) : 'a -> 'a -> boolSmaller or equal comparator
(>=) : 'a -> 'a -> boolGreater or equal comparator
All of these functions are generally O(1) in Space and Time complexity unless other specified
Complexity may differ depending on the provided type
'a
compare : 'a -> 'a -> intReturns a positive integer when x > y, negative if x < y, and 0 if x = y
max : 'a -> 'a -> 'aReturns the largest element in a set of two
min : 'a -> 'a -> 'aReturns the smallest element in a set of two
print_int : int -> unitPrint an integer
print_float : float -> unitPrint a real number
print_string : string -> unitPrint a string
print_newline : unit -> unitPrint a line return character
'a_of_stringfunctions are O(N) with N length of the string. This should be considered O(1) for most applications
ignore : 'a -> unitCast value to unit
float_of_int : int -> floatCast integer to float
int_of_float : float -> intCast a real number to the integer of its truncated decimal representation
string_of_int : int -> stringInteger to string
int_of_string : string -> intParse a string as an integer
string_of_float : float -> stringFloat to string
float_of_string : string -> floatParse a string as a floating number
Only type member: ()
Warning: Tests for unit should use = and <>, not == and !=
All of these operators are O(1) in Space and Time complexity
(not) : bool -> boolFormal negation
(&&) : bool -> bool -> boolFormal logical AND
(||) : bool -> bool -> boolFormal logical OR
(+) : int -> int -> intInteger addition
(-) : int -> int -> intInteger difference
( * ) : int -> int -> intInteger multiplication
(/) : int -> int -> intInteger division quotient
(mod) : int -> int -> intInteger division remainder
abs : int -> intInteger absolute value (canonical distance to 0)
(+.) : flaot -> flaot -> flaotReal number addition
(-.) : float -> float -> floatReal number difference
( *.) : float -> float -> floatReal number multiplication
(/.) : float -> float -> floatReal number division
( ** ) : float -> float -> floatReal number power
sqrt : float -> floatReal square root
exp : float -> floatNatural real exponentiation
log : float -> floatNatural real logarithm
log10 : float -> floatBase 10 real logarithm
sin : float -> floatSine function
cos : float -> floatCosine function
tan : float -> floatTangent function
asin : float -> floatSine's reciprocal function
acos : float -> floatCosine's reciprocal function
atan : float -> floatTangent's reciprocal function
All of these functions are O(1) in Space and Time complexity
fst : ('a, 'b) -> 'aGet first element of a couple
snd : ('a, 'b) -> 'bGet second element of a couple
(^) : string -> string -> stringString concatenation
O(N + M) with N, M lengths of the given strings
str.[idx] -> charEquivalent to String.get str idx
O(1)
String.length : string -> intGet string length
O(1)
String.get : string -> int -> charGet char at given index
O(1)
String.sub : string -> start: int -> lenght: int -> stringCreate substring given start index and length of sub-string
O(N) with N being created string length
String.make : int -> char -> stringCreate a string with given length and filled with given character
O(N) with N string length
String.init : int -> (int -> char) -> stringCreate a string of given length and by using characters returned by given function
O(N) with N string length
(::) : 'a -> 'a list -> 'a listList push to head or pull head
O(1)
(@) : 'a list -> 'a list -> 'a listList concatenation
O(N) with N length of the first list
List.length : 'a list -> intGet list's size
Warning: Never use, this is linear in time
O(N) with N length of the list
List.hd : 'a list -> 'aGet list's head (first element)
O(1)
List.tl : 'a list -> 'a listGet list's tail (list minus list head)
O(1)
List.nth : 'a list -> int -> 'aGet list's nth element
Note: Lists are 0-indexed. First element is at index 0.
Warning: Avoid using, this is linear in time
O(N) with N index of sought element
List.mem : 'a list -> 'a -> boolTest whether second argument is an element of given list
O(N) with N list length
List.rev : 'a list -> 'a listCreate a list with the same elements but with reversed order
O(N) with N list length
List.iter : ('a -> unit) -> 'a list -> unitApplies given function to all elements of the list, from head to tail
O(N) with N list length
List.map : ('a -> 'b) -> 'a list -> 'b listApplies given function to all elements of the list and returns the results as a list
O(N) with N list length
List.fold_right : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'bReduces a list with given function and initial value from tail to head
O(N) with N list length
List.fold_left : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'aSame as List.fold_right but from head to tail and with different argument order
O(N) with N list length
Array.length : 'a array -> intGet array length
O(1)
Array.make : int -> 'a -> 'a arrayCreate an array with given length and filled with given element
O(N) with N array length
Array.make_matrix : int -> int -> 'a -> 'a array arrayCreate a two dimensional array with given width, height and filled with given element
Warning: Watch your steps as filler value is passed by reference and use Array.init instead if necessary
O(N * M) with N, M width and height
Array.init : int -> (int -> 'a) -> 'a arrayCreate an array of given length and by using values returned by given function
O(N) with N array length
let foo = function x -> x + x;;
let foo = fun x -> x + x;;
let foo x = x + x;;Warning: Only function syntax allows for matching
Warning: Recursivity requires rec keyword
let bar = function
| 42 -> "yay"
| _ -> "nay";;Warning: Only function syntax allows for matching
let rec factorial = function
| 0 -> 1
| n -> n * fact (n - 1);;let rec gcd a = function
| 0 -> a
| b -> gcd b (a mod b);;Greatest common denominator of two integers
let string_of_char chr = String.make 1 chr;;let char_of_string str = String.get str 0;;let string_of_array t = String.init (Array.length t) (Array.get t);;Cast a char array into a string
let array_of_string s = Array.init (String.length s) (String.get s);;Cast a string into a char array