Skip to content

Commit

Permalink
New type for Type (part 9).
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoejp committed May 12, 2024
1 parent e49ec99 commit 2308e87
Show file tree
Hide file tree
Showing 21 changed files with 294 additions and 265 deletions.
3 changes: 2 additions & 1 deletion stdlib/source/library/lux/control/pattern.lux
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
or and
is has
try with when
match?)
match?
abstraction)
[abstract
[equivalence (.only Equivalence)]]
[control
Expand Down
92 changes: 44 additions & 48 deletions stdlib/source/library/lux/documentation.lux
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

(the |recursion_dummy|
(template.macro (_)
[{.#Nominal "" {.#Empty}}]))
[{.#Nominal "" (list)}]))

(.every Fragment
(Variant
Expand Down Expand Up @@ -264,30 +264,21 @@
(-> Natural Text Bit Text Type
Text)
(`` (when type
{.#Nominal name params}
(|> params
(stack#each (|>> (%type' level type_function_name false module)
(text " ")))
{.#Top (%.text name)}
list.of_stack
text.together
(text.enclosed ["(Nominal " ")"]))

{.#Sum _}
(type.Sum left right)
(|> type
type.flat_variant
(list#each (%type' level type_function_name false module))
(text.interposed " ")
(text.enclosed ["(Or " ")"]))

{.#Product _}
(type.Product left right)
(|> type
type.flat_tuple
(list#each (%type' level type_function_name false module))
(text.interposed " ")
(text.enclosed ["[" "]"]))

{.#Function input output}
(type.Function input output)
(let [[ins out] (type.flat_function type)]
(text "(-> "
(|> ins
Expand All @@ -297,7 +288,15 @@
(%type' level type_function_name false module out)
")"))

{.#Parameter idx}
{.#Nominal name params}
(|> params
(list#each (function (_ [polarity it])
(%type' level type_function_name false module it)))
(text.interposed " ")
(text (%.text name) " ")
(text.enclosed ["(Nominal " ")"]))

{.#Parameter parameter idx}
(parameter_name [type_function_name (stack)] level idx)

(,, (template.with [<tag>]
Expand All @@ -308,7 +307,7 @@
[.#Opaque]))

(,, (template.with [<tag> <name> <flat>]
[{<tag> _}
[{.#Quantification <tag> _}
(let [[level' body] (<flat> type)
args (level_parameters level level')
body_doc (%type' (n.+ level level') type_function_name nestable? module body)]
Expand All @@ -318,13 +317,13 @@
(text " " body_doc))
")"))]

[.#Universal "All" type.flat_univ_q]
[.#Existential "Ex" type.flat_ex_q]))
[.universal "All" type.flat_univ_q]
[.existential "Ex" type.flat_ex_q]))

{.#Reification (|recursion_dummy|) {.#Parameter 0}}
{.#Reification (|recursion_dummy|) {.#Parameter .abstraction 0}}
type_function_name

{.#Reification (|recursion_dummy|) {.#Universal _ body}}
{.#Reification (|recursion_dummy|) {.#Quantification .universal _ body}}
(text "(Rec " type_function_name
\n (nested " " (%type' level type_function_name nestable? module body))
")")
Expand Down Expand Up @@ -352,7 +351,7 @@
(when arity
0 {.#Some type}
_ (when type
{.#Universal _env _type}
{.#Quantification .universal _env _type}
(parameterized_type (-- arity) _type)

_
Expand All @@ -368,22 +367,7 @@

_
(when type
{.#Nominal name params}
(when params
{.#Empty}
(text "(Nominal " (%.text name) ")")

_
(text "(Nominal "
(%.text name)
" "
(|> params
list.of_stack
(list#each (type_definition' false level arity type_function_info {.#None} module))
(text.interposed " "))
")"))

{.#Sum _}
(type.Sum _ _)
(let [members (type.flat_variant type)]
(when tags
{.#Empty}
Expand All @@ -398,7 +382,7 @@
(list.zipped_2 (list.of_stack tags))
(list#each (function (_ [t_name type])
(when type
{.#Product _}
(type.Product _ _)
(let [types (type.flat_tuple type)]
(text " {" t_name " "
(|> types
Expand All @@ -411,7 +395,7 @@
(text.interposed \n)
(text.enclosed [(text "(Variant" \n) ")"]))))

{.#Product _}
(type.Product _ _)
(let [members (type.flat_tuple type)]
(when tags
{.#Empty}
Expand All @@ -430,7 +414,7 @@
(text.enclosed [" [" "]"])
(text.enclosed [(text "(Record" \n) ")"]))))

{.#Function input output}
(type.Function input output)
(let [[ins out] (type.flat_function type)]
(text "(-> "
(|> ins
Expand All @@ -440,7 +424,20 @@
(type_definition' false level arity type_function_info {.#None} module out)
")"))

{.#Parameter idx}
{.#Nominal name params}
(|> (when params
(list)
(%.text name)

_
(|> params
(list#each (function (_ [polarity it])
(type_definition' false level arity type_function_info {.#None} module it)))
(text.interposed " ")
(text (%.text name) " ")))
(text.enclosed ["(Nominal " ")"]))

{.#Parameter parameter idx}
(parameter_name type_function_info level idx)

(,, (template.with [<pre> <tag>]
Expand All @@ -451,7 +448,7 @@
["+" .#Opaque]))

(,, (template.with [<tag> <name> <flat>]
[{<tag> _}
[{.#Quantification <tag> _}
(let [[level' body] (<flat> type)
args (level_parameters (n.- arity level) level')
body_doc (type_definition' nestable? (n.+ level level') arity type_function_info tags module body)
Expand All @@ -464,14 +461,14 @@
(text " " body_doc))
")"))]

[.#Universal "All" type.flat_univ_q]
[.#Existential "Ex" type.flat_ex_q]))
[.universal "All" type.flat_univ_q]
[.existential "Ex" type.flat_ex_q]))

... Recursive call
{.#Reification (|recursion_dummy|) {.#Parameter 0}}
{.#Reification (|recursion_dummy|) {.#Parameter .abstraction 0}}
(product.left type_function_info)

{.#Reification (|recursion_dummy|) {.#Universal _ body}}
{.#Reification (|recursion_dummy|) {.#Quantification .universal _ body}}
(|> (type_definition' nestable? level arity type_function_info tags module body)
(text.all_split_by \n)
(list#each (text.prefix " "))
Expand Down Expand Up @@ -566,9 +563,8 @@
(, 'module)
[(, (code.text (product.right name))) (stack (,* (list#each code.text parameters)))]
(.stack (,* (|> tags
(try.else (stack))
(stack#each (|>> name.proper code.text))
list.of_stack))))
(try.else (list))
(list#each (|>> name.proper code.text))))))
(text "... " ((debug.private ..type_documentation) (, 'module) (, 'type)) text.\n)
md.raw_code))
(` (md.raw_code ((debug.private ..type_documentation) (, 'module) (, 'type))))))))
Expand Down
3 changes: 1 addition & 2 deletions stdlib/source/library/lux/ffi/export.jvm.lux
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

(.using
[library
[lux (.except #Function
function)
[lux (.except function)
[abstract
["<>" projection]]
[data
Expand Down
2 changes: 1 addition & 1 deletion stdlib/source/library/lux/time/solar.lux
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

(.using
[library
[lux (.except)
[lux (.except universal)
["[0]" ffi]
[abstract
[monad (.only do)]]
Expand Down
10 changes: 7 additions & 3 deletions stdlib/source/library/lux/type/implicit.lux
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
{.#Some sig_type'}
(member_type idx sig_type'))

{.#Product left right}
(//.Product left right)
(if (n.= 0 idx)
(by check.monad in left)
(member_type (-- idx) right))
Expand All @@ -112,7 +112,11 @@
[[this_module_name _] module.current
imp_mods (import.all this_module_name)
tag_stacks (list.each' ! label.tag_stacks imp_mods)
.let [tag_stacks (|> tag_stacks list.as_stack stack#conjoint (stack#each product.left) stack#conjoint)
.let [tag_stacks (|> tag_stacks
list.as_stack
stack#conjoint
(stack#each (|>> product.left list.as_stack))
stack#conjoint)
candidates (stack.only (|>> product.right (text.= simple_name))
tag_stacks)]]
(when candidates
Expand Down Expand Up @@ -230,7 +234,7 @@
maybe.trusted
(on_argument arg)))

{.#Function input output}
(//.Function input output)
(do check.monad
[_ (check.check input arg)]
(in output))
Expand Down
32 changes: 15 additions & 17 deletions stdlib/source/library/lux/type/poly.lux
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

(the recursion_parameter
(template.macro (_)
[{.#Nominal "" {.#Empty}}]))
[{.#Nominal "" (.list)}]))

(the recursive
(template.macro (_ ,type)
Expand All @@ -82,21 +82,21 @@
(the recursion
(template.macro (_)
[{.#Reification (..recursion_parameter)
{.#Parameter 0}}]))
{.#Parameter .abstraction 0}}]))

(the polymorphic
(template.macro (_ ,name ,non_quantified)
[{.#Named ,name {.#Quantification .universal (stack) ,non_quantified}}]))

(every Context
(Dictionary Natural Code))
(Dictionary Natural [Code Code]))

(the empty
Context
(dictionary.empty n.hash))

(the (has solution it)
(-> Code
(-> [Code Code]
(-> Context Context))
(dictionary.has (dictionary.size it) solution it))

Expand All @@ -105,9 +105,7 @@
(-> Context Context))
(let [[_ it] (list#mix (function (_ next [previous it])
[(list#composite previous (list next))
(|> it
(has (` ((, successor) (,* previous))))
(has next))])
(has [(` ((, successor) (,* previous))) next] it)])
[(is (List Code) (list)) it]
predecessors)]
it))
Expand Down Expand Up @@ -184,24 +182,24 @@

{.#None}
(when it
{.#Sum sum}
(//.Sum left right)
(when (its #sum poly)
{#Nested for_sum}
(for_sum (code arity 'recursive context) sum)
(for_sum (code arity 'recursive context) [left right])

{#Flat for_variant}
(for_variant (code arity 'recursive context) (//.flat_variant it)))

{.#Product product}
(//.Product left right)
(when (its #product poly)
{#Nested for_product}
(for_product (code arity 'recursive context) product)
(for_product (code arity 'recursive context) [left right])

{#Flat for_record}
(for_record (code arity 'recursive context) (//.flat_tuple it)))

{.#Function it}
((its #function poly) (code arity 'recursive context) it)
(//.Function cause effect)
((its #function poly) (code arity 'recursive context) [cause effect])

(..recursive it)
((its #recursive poly) (code arity 'recursive context) [(list 'recursive) it])
Expand All @@ -211,7 +209,7 @@

{.#Reification it}
(when it
[{.#Parameter 1} {.#Parameter 0}]
[{.#Parameter .argument 0} {.#Parameter .abstraction 0}]
(when (its #recursion poly)
{.#Some recursion}
(recursion (code arity 'recursive context) (list 'recursive))
Expand All @@ -226,7 +224,7 @@
(code arity 'recursive context)
it))

{.#Parameter index}
{.#Parameter .argument index}
(when (its #parameter poly)
{.#Some parameter}
(parameter (code arity 'recursive context) [arity index])
Expand All @@ -236,8 +234,8 @@
{try.#Failure _}
(exception.except ..invalid [it])

success
success))
{try.#Success [type term]}
{try.#Success term}))

(..polymorphic _ _)
(let [[arity non_quantified] (//.flat_univ_q (//.anonymous it))
Expand Down
2 changes: 1 addition & 1 deletion stdlib/source/library/lux/type/record.lux
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
(list.any? (n.= index) excluded)))
included (|> (when (product.left head)
{.#Some [index exported? cohort]}
(stack.size cohort)
(list.size cohort)

{.#None}
1)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/source/library/lux/type/row.lux
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
{.#Named _ it}
(nesting it)

{.#Existential (stack) un_quantified}
{.#Quantification .existential (stack) un_quantified}
(when (type.flat_reification un_quantified)
[{.#Named [..row_module ..row_proper] _} _]
1
Expand Down

0 comments on commit 2308e87

Please sign in to comment.