Re:The Early History of F# [pdf]
by yawaramin on Saturday June 13, 2020 @02:29PM
(#23511505)
in F#, yes, in TypeScript, not really. The technique involves using a combo of an opaque nominal type, and a smart constructor:
Now, `GreaterThanTwo.make x` gives you a value of type `GreaterThanTwo.t option`, meaning it can be `Some` value or `None`. If it's `Some` value, that means it really does contain an int greater than two and you can get that int using `GreaterThanTwo.to_int`.
[ Parent
| on HN ]
There are no comments on this comment yet.