Last active
June 28, 2018 03:41
-
-
Save cristianoc/791aac26f94dbded0fc137d61f4bd2a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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