From 6fd22846f21b8b70b7867e989109d14a366c0a3e Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 14 Aug 2021 03:09:58 -0400 Subject: Moved documentation-generation machinery to its own module. --- stdlib/source/documentation/lux.lux | 31 +++++++++++++ stdlib/source/documentation/lux/abstract.lux | 42 +++++++++++++++++ stdlib/source/documentation/lux/abstract/apply.lux | 19 ++++++++ stdlib/source/documentation/lux/abstract/codec.lux | 24 ++++++++++ .../source/documentation/lux/abstract/comonad.lux | 29 ++++++++++++ .../documentation/lux/abstract/comonad/cofree.lux | 17 +++++++ stdlib/source/documentation/lux/abstract/enum.lux | 20 ++++++++ .../documentation/lux/abstract/equivalence.lux | 24 ++++++++++ .../source/documentation/lux/abstract/functor.lux | 33 +++++++++++++ .../lux/abstract/functor/contravariant.lux | 15 ++++++ stdlib/source/documentation/lux/abstract/monad.lux | 54 ++++++++++++++++++++++ .../documentation/lux/abstract/monad/free.lux | 18 ++++++++ 12 files changed, 326 insertions(+) create mode 100644 stdlib/source/documentation/lux.lux create mode 100644 stdlib/source/documentation/lux/abstract.lux create mode 100644 stdlib/source/documentation/lux/abstract/apply.lux create mode 100644 stdlib/source/documentation/lux/abstract/codec.lux create mode 100644 stdlib/source/documentation/lux/abstract/comonad.lux create mode 100644 stdlib/source/documentation/lux/abstract/comonad/cofree.lux create mode 100644 stdlib/source/documentation/lux/abstract/enum.lux create mode 100644 stdlib/source/documentation/lux/abstract/equivalence.lux create mode 100644 stdlib/source/documentation/lux/abstract/functor.lux create mode 100644 stdlib/source/documentation/lux/abstract/functor/contravariant.lux create mode 100644 stdlib/source/documentation/lux/abstract/monad.lux create mode 100644 stdlib/source/documentation/lux/abstract/monad/free.lux (limited to 'stdlib/source/documentation') diff --git a/stdlib/source/documentation/lux.lux b/stdlib/source/documentation/lux.lux new file mode 100644 index 000000000..5131a9607 --- /dev/null +++ b/stdlib/source/documentation/lux.lux @@ -0,0 +1,31 @@ +(.module: + [library + [lux + [program (#+ program:)] + ["$" documentation (#+ documentation:)] + ["." debug] + [control + ["." io]]]] + [\\library + ["." /]] + ["." / #_ + ["#." abstract]]) + +(documentation: /.:of + "Generates the type corresponding to a given expression." + [(let [my_num +123] + (:of my_num)) + "=>" + .Int] + [(:of +123) + "=>" + .Int]) + +(.def: .public documentation + (.List $.Module) + ($.module /._ + [..:of] + [/abstract.documentation])) + +(program: inputs + (io.io (debug.log! ($.documentation ..documentation)))) diff --git a/stdlib/source/documentation/lux/abstract.lux b/stdlib/source/documentation/lux/abstract.lux new file mode 100644 index 000000000..a4e7ec807 --- /dev/null +++ b/stdlib/source/documentation/lux/abstract.lux @@ -0,0 +1,42 @@ +(.module: + [library + [lux #* + ["$" documentation (#+ documentation:)] + [data + [text (#+ \n) + ["%" format (#+ format)]] + [collection + ["." list]]]]] + ["." / #_ + ["#." apply] + ["#." codec] + ["#." comonad] + ["#." enum] + ["#." equivalence] + ... ["#." hash] + ... ["#." fold] + ["#." functor] + ... ["#." interval] + ["#." monad] + ... ["#." monoid] + ... ["#." order] + ... ["#." predicate] + ]) + +(.def: .public documentation + (.List $.Module) + (list.joined (list + /apply.documentation + /codec.documentation + /comonad.documentation + /enum.documentation + /equivalence.documentation + ... /hash.documentation + ... /fold.documentation + ... /interval.documentation + ... /monoid.documentation + ... /order.documentation + ... /predicate.documentation + /functor.documentation + /monad.documentation + ))) diff --git a/stdlib/source/documentation/lux/abstract/apply.lux b/stdlib/source/documentation/lux/abstract/apply.lux new file mode 100644 index 000000000..ba611918d --- /dev/null +++ b/stdlib/source/documentation/lux/abstract/apply.lux @@ -0,0 +1,19 @@ +(.module: + [library + [lux + ["$" documentation (#+ documentation:)]]] + [\\library + ["." /]]) + +(documentation: /.Apply + "Applicative functors.") + +(documentation: /.compose + "Applicative functor composition.") + +(.def: .public documentation + (.List $.Module) + ($.module /._ + [..Apply + ..compose] + [])) diff --git a/stdlib/source/documentation/lux/abstract/codec.lux b/stdlib/source/documentation/lux/abstract/codec.lux new file mode 100644 index 000000000..dc83d6fce --- /dev/null +++ b/stdlib/source/documentation/lux/abstract/codec.lux @@ -0,0 +1,24 @@ +(.module: + [library + [lux + ["$" documentation (#+ documentation:)]]] + [\\library + ["." /]]) + +(documentation: /.Codec + "A way to move back-and-forth between a type and an alternative representation for it.") + +(documentation: /.compose + "Codec composition." + [(: (Codec c a) + (compose (: (Codec c b) + cb_codec) + (: (Codec b a) + ba_codec)))]) + +(.def: .public documentation + (.List $.Module) + ($.module /._ + [..Codec + ..compose] + [])) diff --git a/stdlib/source/documentation/lux/abstract/comonad.lux b/stdlib/source/documentation/lux/abstract/comonad.lux new file mode 100644 index 000000000..10f39e86d --- /dev/null +++ b/stdlib/source/documentation/lux/abstract/comonad.lux @@ -0,0 +1,29 @@ +(.module: + [library + [lux + ["$" documentation (#+ documentation:)] + [data + [text (#+ \n) + ["%" format (#+ format)]]]]] + [\\library + ["." /]] + ["." / #_ + ["#." cofree]]) + +(documentation: /.CoMonad + (format "Co-monads are the opposite/complement to monads." + \n "Co-monadic structures are often infinite in size and built upon lazily-evaluated functions.")) + +(documentation: /.be + "A co-monadic parallel to the 'do' macro." + [(let [square (function (_ n) (* n n))] + (be comonad + [inputs (iterate inc +2)] + (square (out inputs))))]) + +(.def: .public documentation + (.List $.Module) + ($.module /._ + [..CoMonad + ..be] + [/cofree.documentation])) diff --git a/stdlib/source/documentation/lux/abstract/comonad/cofree.lux b/stdlib/source/documentation/lux/abstract/comonad/cofree.lux new file mode 100644 index 000000000..332cae864 --- /dev/null +++ b/stdlib/source/documentation/lux/abstract/comonad/cofree.lux @@ -0,0 +1,17 @@ +(.module: + [library + [lux + ["$" documentation (#+ documentation:)]]] + [\\library + ["." /]]) + +(documentation: /.CoFree + "The CoFree CoMonad.") + +(.def: .public documentation + (.List $.Module) + ($.module /._ + [..CoFree + ($.default /.functor) + ($.default /.comonad)] + [])) diff --git a/stdlib/source/documentation/lux/abstract/enum.lux b/stdlib/source/documentation/lux/abstract/enum.lux new file mode 100644 index 000000000..2853ba8ca --- /dev/null +++ b/stdlib/source/documentation/lux/abstract/enum.lux @@ -0,0 +1,20 @@ +(.module: + [library + [lux + ["$" documentation (#+ documentation:)]]] + [\\library + ["." /]]) + +(documentation: /.Enum + "Enumerable types, with a notion of moving forward and backwards through a type's instances.") + +(documentation: /.range + "An inclusive [from, to] range of values." + [(range enum from to)]) + +(.def: .public documentation + (.List $.Module) + ($.module /._ + [..Enum + ..range] + [])) diff --git a/stdlib/source/documentation/lux/abstract/equivalence.lux b/stdlib/source/documentation/lux/abstract/equivalence.lux new file mode 100644 index 000000000..0be66e537 --- /dev/null +++ b/stdlib/source/documentation/lux/abstract/equivalence.lux @@ -0,0 +1,24 @@ +(.module: + [library + [lux + ["$" documentation (#+ documentation:)] + [data + [text (#+ \n) + ["%" format (#+ format)]]]]] + [\\library + ["." /]]) + +(documentation: /.Equivalence + "Equivalence for a type's instances.") + +(documentation: /.rec + "A recursive equivalence combinator." + [(rec recursive_equivalence)]) + +(.def: .public documentation + (.List $.Module) + ($.module /._ + [..Equivalence + ..rec + ($.default /.functor)] + [])) diff --git a/stdlib/source/documentation/lux/abstract/functor.lux b/stdlib/source/documentation/lux/abstract/functor.lux new file mode 100644 index 000000000..1ca3b082a --- /dev/null +++ b/stdlib/source/documentation/lux/abstract/functor.lux @@ -0,0 +1,33 @@ +(.module: + [library + [lux + ["$" documentation (#+ documentation:)] + [data + [text (#+ \n) + ["%" format (#+ format)]]]]] + [\\library + ["." /]] + ["." / #_ + ["#." contravariant]]) + +(documentation: /.sum + "Co-product (sum) composition for functors.") + +(documentation: /.product + "Product composition for functors.") + +(documentation: /.compose + "Functor composition.") + +(.def: .public documentation + (.List $.Module) + ($.module /._ + [($.default /.Functor) + ($.default /.Fix) + ($.default /.Or) + ($.default /.And) + ($.default /.Then) + ..sum + ..product + ..compose] + [/contravariant.documentation])) diff --git a/stdlib/source/documentation/lux/abstract/functor/contravariant.lux b/stdlib/source/documentation/lux/abstract/functor/contravariant.lux new file mode 100644 index 000000000..15f2332ed --- /dev/null +++ b/stdlib/source/documentation/lux/abstract/functor/contravariant.lux @@ -0,0 +1,15 @@ +(.module: + [library + [lux + ["$" documentation (#+ documentation:)]]] + [\\library + ["." /]]) + +(documentation: /.Functor + "The contravariant functor.") + +(.def: .public documentation + (.List $.Module) + ($.module /._ + [..Functor] + [])) diff --git a/stdlib/source/documentation/lux/abstract/monad.lux b/stdlib/source/documentation/lux/abstract/monad.lux new file mode 100644 index 000000000..7293f9a1d --- /dev/null +++ b/stdlib/source/documentation/lux/abstract/monad.lux @@ -0,0 +1,54 @@ +(.module: + [library + [lux + ["$" documentation (#+ documentation:)] + [data + [text (#+ \n) + ["%" format (#+ format)]]]]] + [\\library + ["." /]] + ["." / #_ + ["#." free]]) + +(documentation: /.Monad + (format "A monad is a monoid in the category of endofunctors." + \n "What's the problem?")) + +(documentation: /.do + "Macro for easy concatenation of monadic operations." + [(do monad + [y (f1 x) + z (f2 z)] + (in (f3 z)))]) + +(documentation: /.bind + "Apply a function with monadic effects to a monadic value and yield a new monadic value." + [(bind monad function)]) + +(documentation: /.seq + "Run all the monadic values in the list and produce a list of the base values." + [(seq monad)]) + +(documentation: /.map + "Apply a monadic function to all values in a list." + [(map monad function items)]) + +(documentation: /.only + "Filter the values in a list with a monadic function." + [(only monad predicate items)]) + +(documentation: /.fold + "Fold a list with a monadic function." + [(fold monad function initial_value items)]) + +(.def: .public documentation + (.List $.Module) + ($.module /._ + [..Monad + ..do + ..bind + ..seq + ..map + ..only + ..fold] + [/free.documentation])) diff --git a/stdlib/source/documentation/lux/abstract/monad/free.lux b/stdlib/source/documentation/lux/abstract/monad/free.lux new file mode 100644 index 000000000..c29516a1c --- /dev/null +++ b/stdlib/source/documentation/lux/abstract/monad/free.lux @@ -0,0 +1,18 @@ +(.module: + [library + [lux + ["$" documentation (#+ documentation:)]]] + [\\library + ["." /]]) + +(documentation: /.Free + "The Free Monad.") + +(.def: .public documentation + (.List $.Module) + ($.module /._ + [..Free + ($.default /.functor) + ($.default /.apply) + ($.default /.monad)] + [])) -- cgit v1.2.3