From 2d94e3f1e25a98d0b3a4cf0ebbadd17cc8cc5d32 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 29 Jul 2017 15:51:28 -0400 Subject: - Added Eq, Order and Enum structures for unit types. --- stdlib/source/lux/type/unit.lux | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'stdlib/source') 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]) + ["p" parser "p/" Monad] + [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 (All [unit] (Eq (Qty unit))) + (def: (= reference sample) + (i.= (out reference) (out sample)))) + +(struct: #export Order (All [unit] (Order (Qty unit))) + (def: eq Eq) + + (do-template [ ] + [(def: ( reference sample) + ( (out reference) (out sample)))] + + [< i.<] + [<= i.<=] + [> i.>] + [>= i.>=])) + +(struct: #export Enum (All [unit] (Enum (Qty unit))) + (def: order Order) + (def: (succ qty) (|> (out qty) i.inc (in (carrier qty)))) + (def: (pred qty) (|> (out qty) i.dec (in (carrier qty))))) -- cgit v1.2.3