diff options
author | Eduardo Julian | 2017-07-29 15:51:28 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-07-29 15:51:28 -0400 |
commit | 2d94e3f1e25a98d0b3a4cf0ebbadd17cc8cc5d32 (patch) | |
tree | 543be2469b1198a9a623e192e0f0288bef2712df /stdlib/source | |
parent | f4d7431924312f16e4fbbd7343ca8d548582fded (diff) |
- Added Eq, Order and Enum structures for unit types.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux/type/unit.lux | 26 |
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))))) |