From 75e8244fd7914d2ac0c3622d2277b84c4bfa7ffb Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 4 Jun 2022 20:00:01 -0400 Subject: comonad/cofree => comonad/free --- lux-mode/lux-mode.el | 2 +- stdlib/source/library/lux.lux | 15 +++++-- .../source/library/lux/abstract/comonad/cofree.lux | 27 ------------ .../source/library/lux/abstract/comonad/free.lux | 27 ++++++++++++ stdlib/source/library/lux/control/exception.lux | 2 +- stdlib/source/library/lux/control/maybe.lux | 2 +- stdlib/source/library/lux/control/reader.lux | 2 +- stdlib/source/library/lux/control/state.lux | 2 +- stdlib/source/library/lux/control/try.lux | 2 +- stdlib/source/library/lux/control/writer.lux | 2 +- stdlib/source/library/lux/data/collection/list.lux | 2 +- stdlib/source/library/lux/meta/location.lux | 2 +- .../tool/compiler/language/lux/analysis/module.lux | 2 +- .../tool/compiler/language/lux/analysis/scope.lux | 2 +- .../tool/compiler/language/lux/phase/extension.lux | 2 +- stdlib/source/library/lux/tool/compiler/phase.lux | 2 +- stdlib/source/library/lux/type/check.lux | 2 +- stdlib/source/library/lux/type/implicit.lux | 2 +- stdlib/source/test/lux/abstract.lux | 4 +- stdlib/source/test/lux/abstract/comonad/cofree.lux | 51 ---------------------- stdlib/source/test/lux/abstract/comonad/free.lux | 51 ++++++++++++++++++++++ stdlib/source/test/lux/macro/local.lux | 2 +- 22 files changed, 108 insertions(+), 99 deletions(-) delete mode 100644 stdlib/source/library/lux/abstract/comonad/cofree.lux create mode 100644 stdlib/source/library/lux/abstract/comonad/free.lux delete mode 100644 stdlib/source/test/lux/abstract/comonad/cofree.lux create mode 100644 stdlib/source/test/lux/abstract/comonad/free.lux diff --git a/lux-mode/lux-mode.el b/lux-mode/lux-mode.el index b50d4ac55..a4550d7af 100644 --- a/lux-mode/lux-mode.el +++ b/lux-mode/lux-mode.el @@ -381,7 +381,7 @@ Called by `imenu--generic-function'." (type//capability (altRE "capability:")) ;; Data (data//record (altRE "the" "has" "revised")) - (data//interface (altRE "open:" "implementation" "at")) + (data//interface (altRE "open:" "implementation" "with" "at")) (data//implicit (altRE "implicit:" "a/an" "a" "an")) (data//collection (altRE "list" "partial_list" "sequence" "tree")) ;; Code diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index cdcb304a0..1c550ec22 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -4264,11 +4264,20 @@ _ (failure (..wrong_syntax_error (symbol ..refer))))) +(macro: .public (with tokens) + (case (..parsed (..andP ..anyP ..anyP) + tokens) + {.#Some [implementation expression]} + (meta#in (list (` (..let [(..open (~ (text$ (alias_stand_in 0)))) (~ implementation)] + (~ expression))))) + + {.#None} + (failure (..wrong_syntax_error (symbol ..with))))) + (macro: .public (at tokens) (case tokens - (pattern (list struct [_ {#Symbol member}])) - (meta#in (list (` (..let [(..open (~ (text$ (alias_stand_in 0)))) (~ struct)] - (~ (symbol$ member)))))) + (pattern (list implementation [_ {#Symbol member}])) + (meta#in (list (` (..with (~ implementation) (~ (symbol$ member)))))) (pattern (partial_list struct member args)) (meta#in (list (` ((..at (~ struct) (~ member)) (~+ args))))) diff --git a/stdlib/source/library/lux/abstract/comonad/cofree.lux b/stdlib/source/library/lux/abstract/comonad/cofree.lux deleted file mode 100644 index 2b4ec2b4e..000000000 --- a/stdlib/source/library/lux/abstract/comonad/cofree.lux +++ /dev/null @@ -1,27 +0,0 @@ -(.using - [library - [lux (.except)]] - [// (.only CoMonad) - [// - [functor (.only Functor)]]]) - -(type: .public (CoFree F a) - [a (F (CoFree F a))]) - -(implementation: .public (functor dsl) - (All (_ F) (-> (Functor F) (Functor (CoFree F)))) - - (def: (each f [head tail]) - [(f head) (at dsl each (each f) tail)])) - -(implementation: .public (comonad dsl) - (All (_ F) (-> (Functor F) (CoMonad (CoFree F)))) - - (def: functor (..functor dsl)) - - (def: (out [head tail]) - head) - - (def: (disjoint [head tail]) - [[head tail] - (at dsl each disjoint tail)])) diff --git a/stdlib/source/library/lux/abstract/comonad/free.lux b/stdlib/source/library/lux/abstract/comonad/free.lux new file mode 100644 index 000000000..cba43d06d --- /dev/null +++ b/stdlib/source/library/lux/abstract/comonad/free.lux @@ -0,0 +1,27 @@ +(.using + [library + [lux (.except)]] + [// (.only CoMonad) + [// + [functor (.only Functor)]]]) + +(type: .public (Free F a) + [a (F (Free F a))]) + +(implementation: .public (functor dsl) + (All (_ F) (-> (Functor F) (Functor (Free F)))) + + (def: (each f [head tail]) + [(f head) (at dsl each (each f) tail)])) + +(implementation: .public (comonad dsl) + (All (_ F) (-> (Functor F) (CoMonad (Free F)))) + + (def: functor (..functor dsl)) + + (def: (out [head tail]) + head) + + (def: (disjoint [head tail]) + [[head tail] + (at dsl each disjoint tail)])) diff --git a/stdlib/source/library/lux/control/exception.lux b/stdlib/source/library/lux/control/exception.lux index 7aed1de63..48276683c 100644 --- a/stdlib/source/library/lux/control/exception.lux +++ b/stdlib/source/library/lux/control/exception.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except except) + [lux (.except except with) ["[0]" macro] ["[0]" meta] [abstract diff --git a/stdlib/source/library/lux/control/maybe.lux b/stdlib/source/library/lux/control/maybe.lux index 72b1f30aa..dafd471d1 100644 --- a/stdlib/source/library/lux/control/maybe.lux +++ b/stdlib/source/library/lux/control/maybe.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except list) + [lux (.except list with) [abstract [monoid (.only Monoid)] [equivalence (.only Equivalence)] diff --git a/stdlib/source/library/lux/control/reader.lux b/stdlib/source/library/lux/control/reader.lux index 651ce0eb8..cd2d5b053 100644 --- a/stdlib/source/library/lux/control/reader.lux +++ b/stdlib/source/library/lux/control/reader.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except local) + [lux (.except local with) ["@" target] [abstract [apply (.only Apply)] diff --git a/stdlib/source/library/lux/control/state.lux b/stdlib/source/library/lux/control/state.lux index b5a87549d..798e42b16 100644 --- a/stdlib/source/library/lux/control/state.lux +++ b/stdlib/source/library/lux/control/state.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except local) + [lux (.except local with) [abstract [functor (.only Functor)] [apply (.only Apply)] diff --git a/stdlib/source/library/lux/control/try.lux b/stdlib/source/library/lux/control/try.lux index dd43a0ea1..897ae0adf 100644 --- a/stdlib/source/library/lux/control/try.lux +++ b/stdlib/source/library/lux/control/try.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except) + [lux (.except with) ["@" target] [abstract [apply (.only Apply)] diff --git a/stdlib/source/library/lux/control/writer.lux b/stdlib/source/library/lux/control/writer.lux index 40540eb04..e08e494d1 100644 --- a/stdlib/source/library/lux/control/writer.lux +++ b/stdlib/source/library/lux/control/writer.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except) + [lux (.except with) ["@" target] [abstract [monoid (.only Monoid)] diff --git a/stdlib/source/library/lux/data/collection/list.lux b/stdlib/source/library/lux/data/collection/list.lux index 903d5ae3f..ba1902276 100644 --- a/stdlib/source/library/lux/data/collection/list.lux +++ b/stdlib/source/library/lux/data/collection/list.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except revised all only) + [lux (.except revised all only with) ["@" target] [abstract [monoid (.only Monoid)] diff --git a/stdlib/source/library/lux/meta/location.lux b/stdlib/source/library/lux/meta/location.lux index 640dcee6a..c66147ba8 100644 --- a/stdlib/source/library/lux/meta/location.lux +++ b/stdlib/source/library/lux/meta/location.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except) + [lux (.except with) [abstract [equivalence (.only Equivalence)]]]]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/module.lux b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/module.lux index 9aabc7d10..1a897fb6c 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/module.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/module.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except Label) + [lux (.except Label with) [abstract ["[0]" monad (.only do)]] [control diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/scope.lux b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/scope.lux index bf221d35b..2fa60d94f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/analysis/scope.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/analysis/scope.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except local) + [lux (.except local with) [abstract [monad (.only do)]] [control diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension.lux index 493776886..e2fe1fd05 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except) + [lux (.except with) [abstract [equivalence (.only Equivalence)] [hash (.only Hash)] diff --git a/stdlib/source/library/lux/tool/compiler/phase.lux b/stdlib/source/library/lux/tool/compiler/phase.lux index e3cf241ba..480ad7380 100644 --- a/stdlib/source/library/lux/tool/compiler/phase.lux +++ b/stdlib/source/library/lux/tool/compiler/phase.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except except) + [lux (.except except with) [abstract [functor (.only Functor)] [monad (.only Monad do)]] diff --git a/stdlib/source/library/lux/type/check.lux b/stdlib/source/library/lux/type/check.lux index 497e0e6cc..4e9a81e48 100644 --- a/stdlib/source/library/lux/type/check.lux +++ b/stdlib/source/library/lux/type/check.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except try except) + [lux (.except try except with) ["@" target] [abstract [functor (.only Functor)] diff --git a/stdlib/source/library/lux/type/implicit.lux b/stdlib/source/library/lux/type/implicit.lux index fbe04737a..95e9a53dc 100644 --- a/stdlib/source/library/lux/type/implicit.lux +++ b/stdlib/source/library/lux/type/implicit.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except) + [lux (.except with) [abstract ["[0]" monad (.only do)] ["[0]" equivalence]] diff --git a/stdlib/source/test/lux/abstract.lux b/stdlib/source/test/lux/abstract.lux index 974778af5..b044876aa 100644 --- a/stdlib/source/test/lux/abstract.lux +++ b/stdlib/source/test/lux/abstract.lux @@ -6,7 +6,7 @@ ["[1][0]" apply] ["[1][0]" codec] ["[1][0]" comonad (.only) - ["[1]/[0]" cofree]] + ["[1]/[0]" free]] ["[1][0]" enum] ["[1][0]" equivalence] ["[1][0]" hash] @@ -38,7 +38,7 @@ Test (all _.and /comonad.test - /comonad/cofree.test + /comonad/free.test )) (def: .public test diff --git a/stdlib/source/test/lux/abstract/comonad/cofree.lux b/stdlib/source/test/lux/abstract/comonad/cofree.lux deleted file mode 100644 index 2f2b7569b..000000000 --- a/stdlib/source/test/lux/abstract/comonad/cofree.lux +++ /dev/null @@ -1,51 +0,0 @@ -(.using - [library - [lux (.except) - ["_" test (.only Test)] - [abstract - [functor (.only Functor)] - [comonad (.only CoMonad)] - [\\specification - ["$[0]" functor (.only Injection Comparison)] - ["$[0]" comonad]]] - [control - ["//" continuation]] - [data - [collection - ["[0]" list] - ["[0]" stream (.only Stream) (.open: "[1]#[0]" comonad)]]] - [math - ["[0]" random]]]] - [\\library - ["[0]" /]]) - -(def: (injection value) - (Injection (/.CoFree Stream)) - [value (stream#each injection (stream.repeated value))]) - -(def: (interpret [head tail]) - (All (_ a) (-> (/.CoFree Stream a) (Stream a))) - (|> tail - (stream#each (at (/.comonad stream.functor) out)) - [head] - //.pending)) - -(def: comparison - (Comparison (/.CoFree Stream)) - (function (_ == left right) - (at (list.equivalence ==) = - (stream.first 100 (..interpret left)) - (stream.first 100 (..interpret right))))) - -(def: .public test - Test - (<| (_.covering /._) - (_.for [/.CoFree]) - (all _.and - (_.for [/.functor] - ($functor.spec ..injection ..comparison (is (Functor (/.CoFree Stream)) - (/.functor stream.functor)))) - (_.for [/.comonad] - ($comonad.spec ..injection ..comparison (is (CoMonad (/.CoFree Stream)) - (/.comonad stream.functor)))) - ))) diff --git a/stdlib/source/test/lux/abstract/comonad/free.lux b/stdlib/source/test/lux/abstract/comonad/free.lux new file mode 100644 index 000000000..9c84654c2 --- /dev/null +++ b/stdlib/source/test/lux/abstract/comonad/free.lux @@ -0,0 +1,51 @@ +(.using + [library + [lux (.except) + ["_" test (.only Test)] + [abstract + [functor (.only Functor)] + [comonad (.only CoMonad)] + [\\specification + ["$[0]" functor (.only Injection Comparison)] + ["$[0]" comonad]]] + [control + ["//" continuation]] + [data + [collection + ["[0]" list] + ["[0]" stream (.only Stream) (.open: "[1]#[0]" comonad)]]] + [math + ["[0]" random]]]] + [\\library + ["[0]" /]]) + +(def: (injection value) + (Injection (/.Free Stream)) + [value (stream#each injection (stream.repeated value))]) + +(def: (interpret [head tail]) + (All (_ a) (-> (/.Free Stream a) (Stream a))) + (|> tail + (stream#each (at (/.comonad stream.functor) out)) + [head] + //.pending)) + +(def: comparison + (Comparison (/.Free Stream)) + (function (_ == left right) + (at (list.equivalence ==) = + (stream.first 100 (..interpret left)) + (stream.first 100 (..interpret right))))) + +(def: .public test + Test + (<| (_.covering /._) + (_.for [/.Free]) + (all _.and + (_.for [/.functor] + ($functor.spec ..injection ..comparison (is (Functor (/.Free Stream)) + (/.functor stream.functor)))) + (_.for [/.comonad] + ($comonad.spec ..injection ..comparison (is (CoMonad (/.Free Stream)) + (/.comonad stream.functor)))) + ))) diff --git a/stdlib/source/test/lux/macro/local.lux b/stdlib/source/test/lux/macro/local.lux index 910ffe079..a38dc8be7 100644 --- a/stdlib/source/test/lux/macro/local.lux +++ b/stdlib/source/test/lux/macro/local.lux @@ -1,6 +1,6 @@ (.using [library - [lux (.except) + [lux (.except with) ["_" test (.only Test)] ["[0]" meta] [abstract -- cgit v1.2.3