From 11713d1ba99ec7e41682addadd2778dc767682a0 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 4 Sep 2021 13:24:23 -0400 Subject: Better type-declaration documentation. --- .../documentation/lux/control/concatenative.lux | 2 +- stdlib/source/library/lux.lux | 12 +++--- stdlib/source/library/lux/control/parser/type.lux | 16 ++++---- stdlib/source/library/lux/documentation.lux | 46 ++++++++++++++-------- stdlib/source/library/lux/type/poly.lux | 2 +- 5 files changed, 45 insertions(+), 33 deletions(-) (limited to 'stdlib') diff --git a/stdlib/source/documentation/lux/control/concatenative.lux b/stdlib/source/documentation/lux/control/concatenative.lux index 2b7b9bf26..b72716a3a 100644 --- a/stdlib/source/documentation/lux/control/concatenative.lux +++ b/stdlib/source/documentation/lux/control/concatenative.lux @@ -60,7 +60,7 @@ (template.identifier ["function_of_arity_" ])] (documentation: - [( )]))] + [( )]))] [1] [2] [3] [4] [5] [6] [7] [8] diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index 7fad8a9a5..1043560c9 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -153,7 +153,7 @@ ({Type ({Type_List ({Type_Pair - (9 #0 Nothing + (9 #0 (0 #0 ["" #End]) (7 #0 #End (1 #0 ... "lux.Primitive" @@ -189,7 +189,7 @@ (2 #0 Name Type)))))))))))))} ("lux type check type" (2 #0 Type Type)))} ("lux type check type" (9 #0 Type List)))} - ("lux type check type" (9 #0 (4 #0 1) (4 #0 0))))) + ("lux type check type" (9 #0 (0 #0 ["" #End]) (4 #0 0))))) [dummy_location (9 #1 #End)] ("Primitive" "Sum" "Product" "Function" "Parameter" "Var" "Ex" "UnivQ" "ExQ" "Apply" "Named") @@ -645,7 +645,7 @@ ("lux def type tagged" Lux (#Named ["library/lux" "Lux"] ({Lux - (#Apply Nothing + (#Apply (0 #0 ["" #End]) (#UnivQ #End (#Product ... info @@ -688,7 +688,7 @@ (#Sum Text (#Product Lux Any))))) ... host Any))))))))))))))} - (#Apply (#Parameter 1) (#Parameter 0)))) + (#Apply (0 #0 ["" #End]) (#Parameter 0)))) (record$ #End) ["info" "source" "location" "current_module" "modules" "scopes" "type_context" "expected" "seed" "scope_type_vars" "extensions" "eval" "host"] .public) @@ -5556,9 +5556,9 @@ (def: (recursive_type g!self g!dummy name body) (-> Code Code Text Code Code) (` ((.All ((~ g!self) (~ g!dummy)) - (~ (let$ (local_identifier$ name) (` (#.Apply .Nothing (~ g!self))) + (~ (let$ (local_identifier$ name) (` (#.Apply (..primitive "") (~ g!self))) body))) - .Nothing))) + (..primitive "")))) (macro: .public (Rec tokens) (case tokens diff --git a/stdlib/source/library/lux/control/parser/type.lux b/stdlib/source/library/lux/control/parser/type.lux index 6c033af34..a28ce4c58 100644 --- a/stdlib/source/library/lux/control/parser/type.lux +++ b/stdlib/source/library/lux/control/parser/type.lux @@ -22,6 +22,9 @@ ["." check]]]] ["." //]) +(template: (|recursion_dummy|) + [(#.Primitive "" #.End)]) + (template [] [(exception: .public ( {type Type}) (exception.report @@ -198,7 +201,7 @@ list.reversed))))] (recur (++ current_arg) (|> env' - (dictionary.has partialI [.Nothing partialC]) + (dictionary.has partialI [(|recursion_dummy|) partialC]) (dictionary.has partial_varI [(#.Parameter partial_varI) partial_varL])) (#.Item partial_varL all_varsL)))) [all_varsL env']))]] @@ -301,20 +304,15 @@ _ (//.failure (exception.error ..not_named inputT))))) -(`` (template: (|nothing|) - [(#.Named [(~~ (static .prelude_module)) "Nothing"] - (#.UnivQ #.End - (#.Parameter 1)))])) - (def: .public (recursive poly) (All (_ a) (-> (Parser a) (Parser [Code a]))) (do {! //.monad} [headT any] (case (type.anonymous headT) - (^ (#.Apply (|nothing|) (#.UnivQ _ headT'))) + (^ (#.Apply (|recursion_dummy|) (#.UnivQ _ headT'))) (do ! [[recT _ output] (|> poly - (with_extension .Nothing) + (with_extension (|recursion_dummy|)) (with_extension headT) (local (list headT')))] (in [recT output])) @@ -328,7 +326,7 @@ [env ..env headT any] (case (type.anonymous headT) - (^multi (^ (#.Apply (|nothing|) (#.Parameter funcT_idx))) + (^multi (^ (#.Apply (|recursion_dummy|) (#.Parameter funcT_idx))) (n.= 0 (adjusted_idx env funcT_idx)) {(dictionary.value 0 env) (#.Some [self_type self_call])}) (in self_call) diff --git a/stdlib/source/library/lux/documentation.lux b/stdlib/source/library/lux/documentation.lux index 59c4b4a32..4c4dd1bdc 100644 --- a/stdlib/source/library/lux/documentation.lux +++ b/stdlib/source/library/lux/documentation.lux @@ -34,6 +34,9 @@ [lux ["." syntax]]]]]]]) +(template: (|recursion_dummy|) + [(#.Primitive "" #.End)]) + (type: Fragment (Variant (#Comment Text) @@ -271,6 +274,12 @@ ([#.UnivQ "All" type.flat_univ_q] [#.ExQ "Ex" type.flat_ex_q]) + (^ (#.Apply (|recursion_dummy|) (#.Parameter 0))) + type_function_name + + (^ (#.Apply (|recursion_dummy|) (#.UnivQ _ body))) + (format "(Rec " type_function_name " " (%type' level type_function_name module body) ")") + (#.Apply param fun) (let [[type_func type_arguments] (type.flat_application type)] (format "(" (%type' level type_function_name module type_func) " " (|> type_arguments (list\each (%type' level type_function_name module)) (text.interposed " ")) ")")) @@ -341,15 +350,16 @@ (case type (#.Product _) (let [types (type.flat_tuple type)] - (format "(#" t_name " " + (format " (#" t_name " " (|> types (list\each (type_definition' level type_function_info #.None module)) (text.interposed " ")) ")")) _ - (format "(#" t_name " " (type_definition' level type_function_info #.None module type) ")")))) - (text.interposed text.new_line)))) + (format " (#" t_name " " (type_definition' level type_function_info #.None module type) ")")))) + (text.interposed text.new_line) + (text.enclosed [(format "(Variant" \n) ")"])))) (#.Product _) (let [members (type.flat_tuple type)] @@ -358,12 +368,13 @@ (format "[" (|> members (list\each (type_definition' level type_function_info #.None module)) (text.interposed " ")) "]") _ - (let [member_docs (|> members - (list.zipped/2 tags) - (list\each (function (_ [t_name type]) - (format "#" t_name " " (type_definition' level type_function_info #.None module type)))) - (text.interposed (format text.new_line " ")))] - (format "{" member_docs "}")))) + (|> members + (list.zipped/2 tags) + (list\each (function (_ [t_name type]) + (format "#" t_name " " (type_definition' level type_function_info #.None module type)))) + (text.interposed (format \n " ")) + (text.enclosed [" [" "]"]) + (text.enclosed [(format "(Record" \n) ")"])))) (#.Function input output) (let [[ins out] (type.flat_function type)] @@ -401,13 +412,16 @@ [#.ExQ "Ex" type.flat_ex_q]) ... Recursive call - (#.Apply (#.Parameter param_id) (#.Parameter fn_id)) - (if (n.= fn_id param_id) - (product.left type_function_info) - (let [[type_func type_arguments] (type.flat_application type)] - (format "(" (type_definition' level type_function_info tags module (#.Parameter fn_id)) - " " (type_definition' level type_function_info tags module (#.Parameter param_id)) - ")"))) + (^ (#.Apply (|recursion_dummy|) (#.Parameter 0))) + (product.left type_function_info) + + (^ (#.Apply (|recursion_dummy|) (#.UnivQ _ body))) + (|> (type_definition' level type_function_info tags module body) + (text.all_split_by \n) + (list\each (text.prefix " ")) + (text.interposed \n) + (text.enclosed [(format "(Rec " (product.left type_function_info) \n) + ")"])) (#.Apply param fun) (let [[type_func type_arguments] (type.flat_application type)] diff --git a/stdlib/source/library/lux/type/poly.lux b/stdlib/source/library/lux/type/poly.lux index f4b2e0d4f..108cca485 100644 --- a/stdlib/source/library/lux/type/poly.lux +++ b/stdlib/source/library/lux/type/poly.lux @@ -88,7 +88,7 @@ (|> (dictionary.value idx env) maybe.trusted product.left (code env)) (` (.$ (~ (code.nat (-- idx))))))) - (#.Apply (#.Named [(~~ (static .prelude_module)) "Nothing"] _) + (#.Apply (#.Primitive "" #.End) (#.Parameter idx)) (case (.adjusted_idx env idx) 0 (|> env (dictionary.value 0) maybe.trusted product.left (code env)) -- cgit v1.2.3