diff options
author | Mike Gerwitz <mike.gerwitz@rtspecialty.com> | 2018-07-12 16:41:03 -0400 |
---|---|---|
committer | Mike Gerwitz <mike.gerwitz@rtspecialty.com> | 2018-09-11 09:30:54 -0400 |
commit | 6c4d0dae4ad38448cd5837ebb7031a0977dd3538 (patch) | |
tree | 9403d5b8745a85e04d8b9970addd986af57f6406 /core | |
parent | 368b50d026f9bf8c3305f8d30f8ee7d192123fe3 (diff) | |
download | tame-6c4d0dae4ad38448cd5837ebb7031a0977dd3538.tar.gz tame-6c4d0dae4ad38448cd5837ebb7031a0977dd3538.tar.bz2 tame-6c4d0dae4ad38448cd5837ebb7031a0977dd3538.zip |
base: Add maybe type
* base.xml (maybe, nothing): New types.
(boolean): Move into `maybe' as union member.
Diffstat (limited to 'core')
-rw-r--r-- | core/base.xml | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/core/base.xml b/core/base.xml index 78b4ed0..099055b 100644 --- a/core/base.xml +++ b/core/base.xml @@ -80,14 +80,6 @@ </typedef> - <typedef name="boolean" desc="Boolean values"> - <enum type="integer"> - <item name="TRUE" value="1" desc="True" /> - <item name="FALSE" value="0" desc="False" /> - </enum> - </typedef> - - \ref{empty} does not have much use outside of the compiler. <typedef name="empty" @@ -98,6 +90,43 @@ </section> + <section title="Boolean and Unknown"> + \ref{boolean} contains the boolean \ref{TRUE} and~\ref{FALSE} values, + which map to~$1$ and~$0$ respectively. + The \ref{maybe} type is the union of \ref{boolean} and \ref{NOTHING}, + with a value of~$-1$;\footnote{ + This is similar in spirit to the Haskell \tt{Maybe} type, + or the OCaml \tt{Option} type. + }this is commonly used to represent an unknown state or missing + value.\footnote{ + The \ref{nothing}~type is used for the sake of the union; + it should not be used directly.} + + <typedef name="maybe" desc="Boolean or unknown value"> + <union> + <typedef name="nothing" desc="Unknown value"> + <enum type="integer"> + <item name="NOTHING" value="-1" desc="Unknown or missing value" /> + </enum> + </typedef> + + <typedef name="boolean" desc="Boolean values"> + <enum type="integer"> + <item name="TRUE" value="1" desc="True" /> + <item name="FALSE" value="0" desc="False" /> + </enum> + </typedef> + </union> + </typedef> + + The constant \ref{UNKNOWN} is also defined as~$-1$ to serve as an + alternative to the term~``nothing''. + + <const name="UNKNOWN" value="-1" + desc="Unknown or missing value" /> + </section> + + <section title="Convenience"> $0$~is a~common value. Where a value is required (such |