diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/type/unit.lux | 94 |
1 files changed, 54 insertions, 40 deletions
diff --git a/stdlib/source/library/lux/type/unit.lux b/stdlib/source/library/lux/type/unit.lux index b04ad62e9..3348ded53 100644 --- a/stdlib/source/library/lux/type/unit.lux +++ b/stdlib/source/library/lux/type/unit.lux @@ -8,7 +8,7 @@ [order (#+ Order)] [enum (#+ Enum)]] [control - ["<>" parser + ["<>" parser ("#\." monad) ["<.>" code (#+ Parser)]]] [data [text @@ -16,7 +16,6 @@ [macro ["." code] [syntax (#+ syntax:) - ["|.|" export] ["|.|" annotations]]] [math [number @@ -26,7 +25,9 @@ [type abstract]]]) -(abstract: #export (Qty unit) +(abstract: .public (Qty unit) + {} + Int (def: in @@ -38,7 +39,7 @@ (|>> :representation)) (template [<name> <op>] - [(def: #export (<name> param subject) + [(def: .public (<name> param subject) (All [unit] (-> (Qty unit) (Qty unit) (Qty unit))) (:abstraction (<op> (:representation param) (:representation subject))))] @@ -48,7 +49,7 @@ ) (template [<name> <op> <p> <s> <p*s>] - [(def: #export (<name> param subject) + [(def: .public (<name> param subject) (All [p s] (-> (Qty <p>) (Qty <s>) (Qty <p*s>))) (:abstraction (<op> (:representation param) (:representation subject))))] @@ -58,13 +59,13 @@ ) ) -(interface: #export (Unit a) +(interface: .public (Unit a) (: (-> Int (Qty a)) in) (: (-> (Qty a) Int) out)) -(interface: #export (Scale s) +(interface: .public (Scale s) (: (All [u] (-> (Qty u) (Qty (s u)))) scale) (: (All [u] (-> (Qty (s u)) (Qty u))) @@ -72,30 +73,36 @@ (: Ratio ratio)) -(type: #export Pure +(type: .public Pure (Qty Any)) -(def: #export pure +(def: .public pure (-> Int Pure) ..in) -(def: #export number +(def: .public number (-> Pure Int) ..out) -(syntax: #export (unit: - {export |export|.parser} - {type_name <code>.local_identifier} - {unit_name <code>.local_identifier} - {annotations (<>.else |annotations|.empty |annotations|.parser)}) +(def: unitP + (Parser [Code Text Text |annotations|.Annotations]) + (let [private ($_ <>.and + <code>.local_identifier + <code>.local_identifier + (<>.else |annotations|.empty |annotations|.parser))] + (<>.either (<>.and <code>.any private) + (<>.and (<>\in (` .private)) private)))) + +(syntax: .public (unit: + {[export_policy type_name unit_name annotations] ..unitP}) (do meta.monad [@ meta.current_module_name .let [g!type (code.local_identifier type_name)]] - (in (list (` (type: (~+ (|export|.format export)) (~ g!type) + (in (list (` (type: (~ export_policy) (~ g!type) (~ (|annotations|.format annotations)) (primitive (~ (code.text (%.name [@ type_name])))))) - (` (implementation: (~+ (|export|.format export)) (~ (code.local_identifier unit_name)) + (` (implementation: (~ export_policy) (~ (code.local_identifier unit_name)) (..Unit (~ g!type)) (def: (~' in) (~! ..in)) @@ -113,20 +120,27 @@ (n.> 0 denominator))] (in [numerator denominator])))) -(syntax: #export (scale: - {export |export|.parser} - {type_name <code>.local_identifier} - {scale_name <code>.local_identifier} - {(^slots [#ratio.numerator #ratio.denominator]) ..scale} - {annotations (<>.else |annotations|.empty |annotations|.parser)}) +(def: scaleP + (Parser [Code Text Text Ratio |annotations|.Annotations]) + (let [private ($_ <>.and + <code>.local_identifier + <code>.local_identifier + ..scale + (<>.else |annotations|.empty |annotations|.parser))] + (<>.either (<>.and <code>.any private) + (<>.and (<>\in (` .private)) private)))) + +(syntax: .public (scale: + {[export_policy type_name scale_name ratio annotations] ..scaleP}) (do meta.monad - [@ meta.current_module_name + [.let [(^slots [#ratio.numerator #ratio.denominator]) ratio] + @ meta.current_module_name .let [g!scale (code.local_identifier type_name)]] - (in (list (` (type: (~+ (|export|.format export)) ((~ g!scale) (~' u)) + (in (list (` (type: (~ export_policy) ((~ g!scale) (~' u)) (~ (|annotations|.format annotations)) (primitive (~ (code.text (%.name [@ type_name]))) [(~' u)]))) - (` (implementation: (~+ (|export|.format export)) (~ (code.local_identifier scale_name)) + (` (implementation: (~ export_policy) (~ (code.local_identifier scale_name)) (..Scale (~ g!scale)) (def: (~' scale) @@ -143,7 +157,7 @@ [(~ (code.nat numerator)) (~ (code.nat denominator))]))) )))) -(def: #export (re_scaled from to quantity) +(def: .public (re_scaled from to quantity) (All [si so u] (-> (Scale si) (Scale so) (Qty (si u)) (Qty (so u)))) (let [[numerator denominator] (ratio./ (\ from ratio) (\ to ratio))] @@ -153,26 +167,26 @@ (i./ (.int denominator)) in))) -(scale: #export Kilo kilo [1 1,000]) -(scale: #export Mega mega [1 1,000,000]) -(scale: #export Giga giga [1 1,000,000,000]) +(scale: .public Kilo kilo [1 1,000]) +(scale: .public Mega mega [1 1,000,000]) +(scale: .public Giga giga [1 1,000,000,000]) -(scale: #export Milli milli [ 1,000 1]) -(scale: #export Micro micro [ 1,000,000 1]) -(scale: #export Nano nano [1,000,000,000 1]) +(scale: .public Milli milli [ 1,000 1]) +(scale: .public Micro micro [ 1,000,000 1]) +(scale: .public Nano nano [1,000,000,000 1]) -(unit: #export Gram gram) -(unit: #export Meter meter) -(unit: #export Litre litre) -(unit: #export Second second) +(unit: .public Gram gram) +(unit: .public Meter meter) +(unit: .public Litre litre) +(unit: .public Second second) -(implementation: #export equivalence +(implementation: .public equivalence (All [unit] (Equivalence (Qty unit))) (def: (= reference sample) (i.= (..out reference) (..out sample)))) -(implementation: #export order +(implementation: .public order (All [unit] (Order (Qty unit))) (def: &equivalence ..equivalence) @@ -180,7 +194,7 @@ (def: (< reference sample) (i.< (..out reference) (..out sample)))) -(implementation: #export enum +(implementation: .public enum (All [unit] (Enum (Qty unit))) (def: &order ..order) |