- 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 -> bool
Value equality
(<>) : 'a -> 'a -> bool
Value inequality
(==) : 'a -> 'a -> bool
Identity equality
(!=) : 'a -> 'a -> bool
Identity inequality
(<) : 'a -> 'a -> bool
Strictly smaller comparator
(>) : 'a -> 'a -> bool
Strictly greater comparator
(<=) : 'a -> 'a -> bool
Smaller or equal comparator
(>=) : 'a -> 'a -> bool
Greater 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 -> int
Returns a positive integer when x > y, negative if x < y, and 0 if x = y
max : 'a -> 'a -> 'a
Returns the largest element in a set of two
min : 'a -> 'a -> 'a
Returns the smallest element in a set of two
print_int : int -> unit
Print an integer
print_float : float -> unit
Print a real number
print_string : string -> unit
Print a string
print_newline : unit -> unit
Print a line return character
'a_of_string
functions are O(N) with N length of the string. This should be considered O(1) for most applications
ignore : 'a -> unit
Cast value to unit
float_of_int : int -> float
Cast integer to float
int_of_float : float -> int
Cast a real number to the integer of its truncated decimal representation
string_of_int : int -> string
Integer to string
int_of_string : string -> int
Parse a string as an integer
string_of_float : float -> string
Float to string
float_of_string : string -> float
Parse 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 -> bool
Formal negation
(&&) : bool -> bool -> bool
Formal logical AND
(||) : bool -> bool -> bool
Formal logical OR
(+) : int -> int -> int
Integer addition
(-) : int -> int -> int
Integer difference
( * ) : int -> int -> int
Integer multiplication
(/) : int -> int -> int
Integer division quotient
(mod) : int -> int -> int
Integer division remainder
abs : int -> int
Integer absolute value (canonical distance to 0)
(+.) : flaot -> flaot -> flaot
Real number addition
(-.) : float -> float -> float
Real number difference
( *.) : float -> float -> float
Real number multiplication
(/.) : float -> float -> float
Real number division
( ** ) : float -> float -> float
Real number power
sqrt : float -> float
Real square root
exp : float -> float
Natural real exponentiation
log : float -> float
Natural real logarithm
log10 : float -> float
Base 10 real logarithm
sin : float -> float
Sine function
cos : float -> float
Cosine function
tan : float -> float
Tangent function
asin : float -> float
Sine's reciprocal function
acos : float -> float
Cosine's reciprocal function
atan : float -> float
Tangent's reciprocal function
All of these functions are O(1) in Space and Time complexity
fst : ('a, 'b) -> 'a
Get first element of a couple
snd : ('a, 'b) -> 'b
Get second element of a couple
(^) : string -> string -> string
String concatenation
O(N + M) with N, M lengths of the given strings
str.[idx] -> char
Equivalent to String.get str idx
O(1)
String.length : string -> int
Get string length
O(1)
String.get : string -> int -> char
Get char at given index
O(1)
String.sub : string -> start: int -> lenght: int -> string
Create substring given start index and length of sub-string
O(N) with N being created string length
String.make : int -> char -> string
Create a string with given length and filled with given character
O(N) with N string length
String.init : int -> (int -> char) -> string
Create a string of given length and by using characters returned by given function
O(N) with N string length
(::) : 'a -> 'a list -> 'a list
List push to head or pull head
O(1)
(@) : 'a list -> 'a list -> 'a list
List concatenation
O(N) with N length of the first list
List.length : 'a list -> int
Get list's size
Warning: Never use, this is linear in time
O(N) with N length of the list
List.hd : 'a list -> 'a
Get list's head (first element)
O(1)
List.tl : 'a list -> 'a list
Get list's tail (list minus list head)
O(1)
List.nth : 'a list -> int -> 'a
Get 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 -> bool
Test whether second argument is an element of given list
O(N) with N list length
List.rev : 'a list -> 'a list
Create a list with the same elements but with reversed order
O(N) with N list length
List.iter : ('a -> unit) -> 'a list -> unit
Applies 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 list
Applies 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 -> 'b
Reduces 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 -> 'a
Same as List.fold_right
but from head to tail and with different argument order
O(N) with N list length
Array.length : 'a array -> int
Get array length
O(1)
Array.make : int -> 'a -> 'a array
Create an array with given length and filled with given element
O(N) with N array length
Array.make_matrix : int -> int -> 'a -> 'a array array
Create 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 array
Create 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