From d5d5fcc3a85ef10081772355fc20932b387a35ab Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 14 Jun 2022 22:39:09 -0400 Subject: De-sigil-ification: suffix : [Part 10] --- .../source/library/lux/data/format/css/value.lux | 22 +-- .../tool/compiler/language/lux/analysis/type.lux | 2 +- stdlib/source/library/lux/type/unit.lux | 153 ++++++++++----------- stdlib/source/test/lux/type/unit.lux | 6 +- 4 files changed, 92 insertions(+), 91 deletions(-) (limited to 'stdlib') diff --git a/stdlib/source/library/lux/data/format/css/value.lux b/stdlib/source/library/lux/data/format/css/value.lux index 79636d63a..e2bf08a20 100644 --- a/stdlib/source/library/lux/data/format/css/value.lux +++ b/stdlib/source/library/lux/data/format/css/value.lux @@ -50,14 +50,6 @@ (template.spliced +))])) -(def: multi: - (template (multi: ) - [(def: .public ( pre post) - (-> (Value ) (Value ) (Value )) - (abstraction (format (representation pre) - - (representation post))))])) - (def: (%number value) (Format Frac) (let [raw (%.frac value)] @@ -1334,9 +1326,17 @@ (%.int index) (%.nat (.nat index))))) - (multi: multi_image Image ",") - (multi: multi_shadow Shadow ",") - (multi: multi_content Content " ") + (with_template [ ] + [(def: .public ( pre post) + (-> (Value ) (Value ) (Value )) + (abstraction (format (representation pre) + + (representation post))))] + + ["," Image multi_image] + ["," Shadow multi_shadow] + [" " Content multi_content] + ) ... https://developer.mozilla.org/en-US/docs/Web/CSS/calc() (with_template [ ] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/type.lux b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/type.lux index f1a2943ff..dba3ad176 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/type.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/type.lux @@ -57,7 +57,7 @@ (Operation Type) (do phase.monad [module (extension.lifted meta.current_module_name) - [id _] (..check check.existential)] + id (extension.lifted meta.seed)] (in (..existential' module id)))) (def: .public (expecting expected) diff --git a/stdlib/source/library/lux/type/unit.lux b/stdlib/source/library/lux/type/unit.lux index bae4b1bfb..6c6fec8a3 100644 --- a/stdlib/source/library/lux/type/unit.lux +++ b/stdlib/source/library/lux/type/unit.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except) + [lux (.except type) ["[0]" meta] [abstract [monad (.only Monad do)] @@ -13,7 +13,7 @@ [data ["[0]" text (.only) ["%" \\format (.only format)]]] - [macro + ["[0]" macro (.only) ["[0]" code] ["[0]" template] [syntax (.only syntax) @@ -22,21 +22,45 @@ [number ["n" nat] ["i" int] - ["[0]" ratio (.only Ratio)]]] - [type - [primitive (.except)]]]]) + ["[0]" ratio (.only Ratio)]]]]] + ["[0]" // (.only) + [primitive (.except)]]) (primitive: .public (Qty unit) Int - - (def: in' - (All (_ unit) (-> Int (Qty unit))) + + (type: .public Pure + (Qty Any)) + + (def: .public pure + (-> Int Pure) (|>> abstraction)) - (def: out' - (All (_ unit) (-> (Qty unit) Int)) + (def: .public number + (-> Pure Int) (|>> representation)) + (def: .public equivalence + (All (_ unit) (Equivalence (Qty unit))) + (implementation + (def: (= reference sample) + (i.= (representation reference) (representation sample))))) + + (def: .public order + (All (_ unit) (Order (Qty unit))) + (implementation + (def: equivalence ..equivalence) + + (def: (< reference sample) + (i.< (representation reference) (representation sample))))) + + (def: .public enum + (All (_ unit) (Enum (Qty unit))) + (implementation + (def: order ..order) + (def: succ (|>> representation ++ abstraction)) + (def: pred (|>> representation -- abstraction)))) + (with_template [ ] [(def: .public ( param subject) (All (_ unit) (-> (Qty unit) (Qty unit) (Qty unit))) @@ -56,14 +80,50 @@ [* i.* p s [p s]] [/ i./ p [p s] s] ) + + (type: .public (Unit a) + (Interface + (is (-> Int (Qty a)) + in) + (is (-> (Qty a) Int) + out))) + + (def: .public (unit _) + (Ex (_ a) (-> Any (Unit a))) + (implementation + (def: in (|>> abstraction)) + (def: out (|>> representation)))) + + (def: in' + (All (_ unit) (-> Int (Qty unit))) + (|>> abstraction)) + + (def: out' + (All (_ unit) (-> (Qty unit) Int)) + (|>> representation)) ) -(type: .public (Unit a) - (Interface - (is (-> Int (Qty a)) - in) - (is (-> (Qty a) Int) - out))) +(def: .public type + (syntax (_ [it .any]) + (macro.with_symbols [g!a] + (in (list (` ((~! //.by_example) [(~ g!a)] + (Unit (~ g!a)) + (~ it) + + (~ g!a)))))))) + +(with_template [ ] + [(def: .public + (..unit [])) + + (type: .public + (~ (..type )))] + + [gram Gram] + [meter Meter] + [litre Litre] + [second Second] + ) (type: .public (Scale s) (Interface @@ -74,36 +134,6 @@ (is Ratio ratio))) -(type: .public Pure - (Qty Any)) - -(def: .public pure - (-> Int Pure) - ..in') - -(def: .public number - (-> Pure Int) - ..out') - -(def: .public unit: - (syntax (_ [[export_policy type_name unit_name] - (|export|.parser - (all <>.and - .local - .local))]) - (do meta.monad - [@ meta.current_module_name - .let [g!type (code.local type_name)]] - (in (list (` (type: (~ export_policy) (~ g!type) - (Primitive (~ (code.text (%.symbol [@ type_name])))))) - - (` (def: (~ export_policy) (~ (code.local unit_name)) - (..Unit (~ g!type)) - (implementation - (def: (~' in) (~! ..in')) - (def: (~' out) (~! ..out'))))) - ))))) - (def: scaleP (Parser Ratio) (.tuple (do <>.monad @@ -174,34 +204,3 @@ [Micro 1,000,000 1] [Nano 1,000,000,000 1] ) - -(with_template [] - [(`` (unit: .public - (~~ (implementation_name ))))] - - [Gram] - [Meter] - [Litre] - [Second] - ) - -(def: .public equivalence - (All (_ unit) (Equivalence (Qty unit))) - (implementation - (def: (= reference sample) - (i.= (..out' reference) (..out' sample))))) - -(def: .public order - (All (_ unit) (Order (Qty unit))) - (implementation - (def: equivalence ..equivalence) - - (def: (< reference sample) - (i.< (..out' reference) (..out' sample))))) - -(def: .public enum - (All (_ unit) (Enum (Qty unit))) - (implementation - (def: order ..order) - (def: succ (|>> ..out' ++ ..in')) - (def: pred (|>> ..out' -- ..in')))) diff --git a/stdlib/source/test/lux/type/unit.lux b/stdlib/source/test/lux/type/unit.lux index 1006d9dbb..b4662133e 100644 --- a/stdlib/source/test/lux/type/unit.lux +++ b/stdlib/source/test/lux/type/unit.lux @@ -45,7 +45,8 @@ ($enum.spec /.enum (..meter 1,000))) )) -(/.unit: What what) +(def: what (/.unit [])) +(def: What (/.type what)) (def: unit Test @@ -70,9 +71,10 @@ /.pure /.number (i.= expected))) - (_.coverage [/.unit:] + (_.coverage [/.unit /.type] (|> expected (at ..what in) + (is (/.Qty What)) (at ..what out) (i.= expected))) ))))) -- cgit v1.2.3