aboutsummaryrefslogtreecommitdiff
path: root/lib/DATS/valid.dats
diff options
context:
space:
mode:
authorXander <xander@biltopia.org>2023-08-17 22:08:21 +0200
committerXander <xander@biltopia.org>2023-08-17 22:08:21 +0200
commitd177285a761de33b86fcbde72fd718137bfa6f86 (patch)
tree3a880d6df65418ea591be69cf36fd3da8e679f07 /lib/DATS/valid.dats
parente2d7deb82cd25b47cbccda0c48ab39e17c5c536d (diff)
downloadats-os-d177285a761de33b86fcbde72fd718137bfa6f86.tar.xz
ats-os-d177285a761de33b86fcbde72fd718137bfa6f86.zip
Add valid/unvalid type, replacement of optional
Diffstat (limited to 'lib/DATS/valid.dats')
-rw-r--r--lib/DATS/valid.dats15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/DATS/valid.dats b/lib/DATS/valid.dats
new file mode 100644
index 0000000..f4ea0aa
--- /dev/null
+++ b/lib/DATS/valid.dats
@@ -0,0 +1,15 @@
+#define ATS_DYNLOADFLAG 0
+staload "lib/SATS/valid.sats"
+
+assume valid(a:t@ype,b:bool) = (a,bool b)
+
+implement{a} create_valid(value : a) = (value,true)
+
+// Create unvalid value by casting null pointer to type.
+implement{a} create_unvalid() = let
+ staload UN = "prelude/SATS/unsafe.sats"
+in
+ ($UN.ptr0_get<a>(the_null_ptr),false) //UNSAFE:
+end
+
+implement{a} unwrap_valid(v) = v.0