Abstract
A type for signifing missing values.
Synopsis
| type opt 'a = #none | #some a | ||
| val add_identity | 'a : | (op: a -> a -> a) -> (a: #none | #some a) -> (b: #none | #some a) -> opt a |
| val from_opt | 'a : | (ne: a) -> (a: #none | #some a) -> a |
| val map_opt | 'a 'b : | (f: a -> b) -> (x: #none | #some a) -> opt b |
| val equal_opt | 'a : | (eq: a -> a -> bool) -> (a: #none | #some a) -> (b: #none | #some a) -> bool |
| val some | 'a : | (a: a) -> opt a |
| val is_some | 'a : | (a: #none | #some a) -> bool |
| val is_none | 'a : | (a: #none | #some a) -> bool |
| val bind_opt | 'a 'b : | (f: a -> #none | #some b) -> (a: #none | #some a) -> opt b |
| val first_some | 't [d₀] : | (xs: [d₀]#none | #some t) -> opt t |
Description
- ↑val add_identity 'a: (op: a -> a -> a) -> (a: #none | #some a) -> (b: #none | #some a) -> opt a
Extents a binary operation to have
#noneas a identity element.This can be used when a associative operation has no neutral element.
- ↑val from_opt 'a: (ne: a) -> (a: #none | #some a) -> a
Unpacks an
optvalue.If
#some athenais returned, otherwiseneis returned.- ↑val map_opt 'a 'b: (f: a -> b) -> (x: #none | #some a) -> opt b
Maps a function inside
opt.Applies the function
fto the value'a.- ↑val equal_opt 'a: (eq: a -> a -> bool) -> (a: #none | #some a) -> (b: #none | #some a) -> bool
Definition of a
optequality.The equality holds if they are both
#noneor they are both#someand the values inside#someare equal.- ↑val some 'a: (a: a) -> opt a
Maps a value to a
opttype.This is syntactic sugar for
#some a, it may be nicer to use then a lambda function.- ↑val bind_opt 'a 'b: (f: a -> #none | #some b) -> (a: #none | #some a) -> opt b
The bind operation for the optional type.
- ↑val first_some 't [d₀]: (xs: [d₀]#none | #some t) -> opt t
Find the first
#someelement if one exists.