aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/type/unit.lux26
1 files changed, 25 insertions, 1 deletions
diff --git a/stdlib/source/lux/type/unit.lux b/stdlib/source/lux/type/unit.lux
index d04951507..bf1863dfa 100644
--- a/stdlib/source/lux/type/unit.lux
+++ b/stdlib/source/lux/type/unit.lux
@@ -1,7 +1,10 @@
(;module:
lux
(lux (control [monad #+ do Monad]
- ["p" parser "p/" Monad<Parser>])
+ ["p" parser "p/" Monad<Parser>]
+ [eq #+ Eq]
+ [order #+ Order]
+ [enum #+ Enum])
(data text/format
(number ["r" ratio]))
[macro]
@@ -157,3 +160,24 @@
(unit: #export Meter)
(unit: #export Litre)
(unit: #export Second)
+
+(struct: #export Eq<Unit> (All [unit] (Eq (Qty unit)))
+ (def: (= reference sample)
+ (i.= (out reference) (out sample))))
+
+(struct: #export Order<Unit> (All [unit] (Order (Qty unit)))
+ (def: eq Eq<Unit>)
+
+ (do-template [<name> <func>]
+ [(def: (<name> reference sample)
+ (<func> (out reference) (out sample)))]
+
+ [< i.<]
+ [<= i.<=]
+ [> i.>]
+ [>= i.>=]))
+
+(struct: #export Enum<Unit> (All [unit] (Enum (Qty unit)))
+ (def: order Order<Unit>)
+ (def: (succ qty) (|> (out qty) i.inc (in (carrier qty))))
+ (def: (pred qty) (|> (out qty) i.dec (in (carrier qty)))))