Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
type other;
let compareOther: (other, other) => int = assert(false);
let equalOther: (other, other) => bool = assert(false);
type runtimeValue =
| Undefined
| BoxUndefined(int)
| Null
| Other(other);
/**
1) Undefined == none < BoxUndefined(1) < BoxUndefined(2) < ... < Null < V(-)
2) x <= y implies some(x) <= some(y)
*/;
let none = Undefined;
let some = rv =>
switch (rv) {
| Undefined => BoxUndefined(1)
| BoxUndefined(n) => BoxUndefined(n + 1)
| Null => Null
| Other(_) => rv
};
let unSome = rv =>
switch (rv) {
| Undefined => assert(false)
| BoxUndefined(n) => BoxUndefined(n - 1)
| Null => Null
| Other(_) => rv
};
let compare = (rv1, rv2) =>
switch (rv1, rv2) {
| (Undefined, Undefined) => 0
| (Undefined, _) => (-1)
| (_, Undefined) => 1
| (BoxUndefined(n), BoxUndefined(m)) => n - m
| (BoxUndefined(_), _) => (-1)
| (_, BoxUndefined(_)) => 1
| (Null, Null) => 0
| (Null, _) => (-1)
| (_, Null) => 1
| (Other(other1), Other(other2)) => compareOther(other1, other2)
};
let equal = ((rv1, rv2)) =>
switch (rv1, rv2) {
| (Undefined, Undefined) => true
| (Undefined, _)
| (_, Undefined) => false
| (BoxUndefined(n), BoxUndefined(m)) => n == m
| (BoxUndefined(_), _)
| (_, BoxUndefined(_)) => false
| (Null, Null) => true
| (Null, _)
| (_, Null) => false
| (Other(other1), Other(other2)) => equalOther(other1, other2)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.