From f634d43988ee12945a2a6d01e27f0bf1837339b5 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 4 May 2024 18:52:26 -0400 Subject: [PATCH] New type for `Type` (part 1). --- stdlib/source/injection/lux/data/binary.lux | 2 +- stdlib/source/library/lux.lux | 209 ++++++++++------- .../language/lux/analysis/inference.lux | 14 +- .../language/lux/phase/analysis/when.lux | 2 +- .../lux/phase/extension/analysis/jvm.lux | 34 +-- .../lux/phase/extension/declaration/jvm.lux | 4 +- .../lux/phase/extension/declaration/lux.lux | 4 +- stdlib/source/library/lux/compiler/type.lux | 216 +++++++++--------- stdlib/source/library/lux/ffi.jvm.lux | 45 ++-- stdlib/source/library/lux/macro/pattern.lux | 1 - .../library/lux/target/jvm/reflection.lux | 13 +- .../library/lux/target/jvm/type/lux.lux | 14 +- stdlib/source/library/lux/type.lux | 40 ++-- stdlib/source/library/lux/type/check.lux | 32 +-- stdlib/source/library/lux/type/nominal.lux | 4 +- stdlib/source/library/lux/type/variance.lux | 2 +- stdlib/source/projection/lux/data/binary.lux | 2 +- stdlib/source/projection/lux/type.lux | 2 +- .../unsafe/lux/data/collection/array.lux | 216 +++++++++--------- 19 files changed, 473 insertions(+), 383 deletions(-) diff --git a/stdlib/source/injection/lux/data/binary.lux b/stdlib/source/injection/lux/data/binary.lux index c0f1d48682..da33d3e426 100644 --- a/stdlib/source/injection/lux/data/binary.lux +++ b/stdlib/source/injection/lux/data/binary.lux @@ -317,7 +317,7 @@ [(.++ offset)] caseT))])] - [00 .#Nominal (..and ..text (..stack again))] + [00 .#Nominal (..and ..text (..list (..and ..bit again)))] [01 .#Sum pair] [02 .#Product pair] [03 .#Function pair] diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index 971f19df02..0b4d1582d6 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -24,14 +24,30 @@ (.is# Type {9 #1 [..prelude "Bit"] - {#0 (.type_name# "bit") {#0}}}) + {#0 (.type_name# "bit") (.list#)}}) + #1) + +(.def# Polarity + (.is# Type + ..Bit) + #1) + +(.def# contra_variant + (.is# Polarity + #0) + #1) + +(.def# co_variant + (.is# Polarity + #1) #1) (.def# Natural (.is# Type {9 #1 [..prelude "Natural"] - {#0 (.type_name# "i64") {#1 {#0 (.type_name# "natural") {#0}} {#0}}}}) + {#0 (.type_name# "i64") + (.list# [..co_variant {#0 (.type_name# "natural") (.list#)}])}}) #1) ... (every .public Any @@ -83,30 +99,22 @@ {4 #0 1}}}}) #1) -... (every .public Label -... [(Maybe [Natural Bit (Stack Name)]) -... Type]) (.def# Label (.is# Type {9 #1 [..prelude "Label"] - {2 #0 - {9 #0 {2 #0 Natural - {2 #0 Bit - {9 #0 Name Stack}}} - Maybe} - Type}}) + (.type# "label")}) #1) (.def# Tag (.is# Type {9 #1 [..prelude "Tag"] - {#0 (.type_name# "tag") {#0}}}) + {#0 (.type_name# "tag") (.list#)}}) #1) (.def# Slot (.is# Type {9 #1 [..prelude "Slot"] - {#0 (.type_name# "slot") {#0}}}) + {#0 (.type_name# "slot") (.list#)}}) #1) (.def# tag @@ -187,31 +195,31 @@ (.is# Type {#Named [..prelude "I64"] {#Universal {#Empty} - {#Nominal (.type_name# "i64") {#Top {#Parameter 1} {#Empty}}}}}) + {#Nominal (.type_name# "i64") (.list# [..co_variant {#Parameter 1}])}}}) #1) (.def# Integer (.is# Type {#Named [..prelude "Integer"] - {#Nominal (.type_name# "i64") {#Top {#Nominal (.type_name# "integer") {#Empty}} {#Empty}}}}) + {#Nominal (.type_name# "i64") (.list# [..co_variant {#Nominal (.type_name# "integer") (.list#)}])}}) #1) (.def# Revolution (.is# Type {#Named [..prelude "Revolution"] - {#Nominal (.type_name# "i64") {#Top {#Nominal (.type_name# "revolution") {#Empty}} {#Empty}}}}) + {#Nominal (.type_name# "i64") (.list# [..co_variant {#Nominal (.type_name# "revolution") (.list#)}])}}) #1) (.def# Decimal (.is# Type {#Named [..prelude "Decimal"] - {#Nominal (.type_name# "decimal") {#Empty}}}) + {#Nominal (.type_name# "decimal") (.list#)}}) #1) (.def# Text (.is# Type {#Named [..prelude "Text"] - {#Nominal (.type_name# "text") {#Empty}}}) + {#Nominal (.type_name# "text") (.list#)}}) #1) (.def# Error @@ -369,7 +377,7 @@ (.is# Type {#Named [..prelude "List"] {#Universal {#Empty} - {#Nominal (.type_name# "list") {#Top {#Parameter 1} {#Empty}}}}}) + {#Nominal (.type_name# "list") (.list# [..co_variant {#Parameter 1}])}}}) .public) (.def# code#form @@ -390,41 +398,28 @@ (.function# _ tokens {#Tuple (annotated tokens)})) #0) -... (every .public Definition -... [Type Any]) (.def# Definition (.is# Type {#Named [..prelude "Definition"] - {#Product Type Any}}) + (.type# "definition")}) .public) -... (every .public Default -... Definition) (.def# Default (.is# Type {#Named [..prelude "Default"] - Definition}) + (.type# "default")}) .public) -... (every .public Alias -... Name) (.def# Alias (.is# Type {#Named [..prelude "Alias"] - Name}) + (.type# "alias")}) .public) -... (every .public Global -... (Variant -... {#Definition Definition} -... {#Alias Alias} -... {#Default Default})) (.def# Global (.is# Type {#Named [..prelude "Global"] - {#Sum Definition - {#Sum Alias - Default}}}) + (.type# "global")}) .public) (.def# global_tags @@ -525,9 +520,9 @@ ... (every .public Module_State ... (Variant -... #Active -... #Compiled -... #Cached)) +... {#Active} +... {#Compiled} +... {#Cached})) (.def# Module_State (.is# Type {#Named [..prelude "Module_State"] @@ -691,7 +686,7 @@ (.def# Macro (.is# Type {#Named [..prelude "Macro"] - {#Nominal (.type_name# "macro") {#Empty}}}) + {#Nominal (.type_name# "macro") (.list#)}}) .public) ... Base functions & macros @@ -1098,8 +1093,11 @@ ... Recur {#Nominal name parameters} - {#Nominal name (stack#each (__adjusted_quantified_type__ permission depth) - parameters)} + {#Nominal name (list#each (function' (_ it) + (.when# it + [polarity it] + [polarity (__adjusted_quantified_type__ permission depth it)])) + parameters)} {#Sum left right} {#Sum (__adjusted_quantified_type__ permission depth left) @@ -1758,7 +1756,7 @@ (the' .public UnQuote Type {#Named [..prelude "UnQuote"] - {#Nominal ".Macro/UnQuote" {#Empty}}}) + {#Nominal ".Macro/UnQuote" (.list#)}}) (the' .public (unquote it) (-> Macro @@ -1773,7 +1771,7 @@ (the' .public Spliced_UnQuote Type {#Named [..prelude "Spliced_UnQuote"] - {#Nominal ".Macro/Spliced_UnQuote" {#Empty}}}) + {#Nominal ".Macro/Spliced_UnQuote" (.list#)}}) (the' .public (spliced_unquote it) (-> Macro @@ -1905,6 +1903,20 @@ right #0)) +(the' .public (not x) + (-> Bit + Bit) + (if x + #0 + #1)) + +(the' .private (bit#= reference it) + (-> Bit Bit + Bit) + (if reference + it + (not it))) + (the' .private (name#= left right) (-> Name Name Bit) @@ -1924,6 +1936,16 @@ #0)) #1)) +(the' .private (list#every? ?) + (for_any (_ it) + (-> (-> it Bit) ($ List it) + Bit)) + (list#mix (function' (_ _2 _1) + (if _1 + (? _2) + #0)) + #1)) + (the' .private (zipped_2 xs ys) (for_any (_ left right) (-> ($ Stack left) ($ Stack right) @@ -1940,6 +1962,12 @@ _ (stack))) +(the' .private (list#zipped_2 xs ys) + (for_any (_ left right) + (-> ($ List left) ($ List right) + ($ List (Tuple left right)))) + (list#of_stack (zipped_2 (list#as_stack xs) (list#as_stack ys)))) + (the' .private (type#= left right) (-> Type Type Bit) @@ -1947,11 +1975,12 @@ [{#Nominal nameL parametersL} {#Nominal nameR parametersR}] (all and' (text#= nameL nameR) - (.i64_=# (stack#size parametersL) (stack#size parametersR)) - (every? (function' (_ l,r) - (let' [[itL itR] l,r] - (type#= itL itR))) - (zipped_2 parametersL parametersR))) + (.i64_=# (list#size parametersL) (list#size parametersR)) + (list#every? (function' (_ l,r) + (let' [[[polarityL itL] [polarityR itR]] l,r] + (and' (bit#= polarityL polarityR) + (type#= itL itR)))) + (list#zipped_2 parametersL parametersR))) [{#Sum leftL rightL} {#Sum leftR rightR}] (all and' @@ -2235,6 +2264,12 @@ [_ {#Tuple @composite elements}] (untemplated_tuple @composite untemplated replace? subst (list#as_stack elements)))) +(the' .private (untemplated_list tokens) + (-> ($ List Code) + Code) + (code#form (.list_composite# (.list# (code#name [..prelude "list#"])) + tokens))) + (the' .public Nominal Macro (macro (_ tokens) @@ -2242,13 +2277,13 @@ (.list# {#Text _ class_name}) (meta#in (list (code#variant (list (code#name [..prelude "#Nominal"]) (code#text class_name) - |#Empty|)))) + (untemplated_list (list)))))) (.list# {#Text _ class_name} {#Tuple _ params}) (meta#in (list (code#variant (list (code#name [..prelude "#Nominal"]) (code#text class_name) - (untemplated_stack (list#as_stack params)))))) + (untemplated_list params))))) _ (failure ..wrong_syntax)))) @@ -2626,7 +2661,7 @@ (.as# Integer (n#/ param subject)))] (.i64_-# flat subject))) -(the' .private (bit#as x) +(the' .private (bit#as_text x) (-> Bit Text) (if x "#1" "#0")) @@ -2680,11 +2715,6 @@ (|> value (.int_/# +10) integer#abs) (|> value (.int_%# +10) integer#abs (.as# Natural) digit::injection))))) -(the' .public (not x) - (-> Bit - Bit) - (if x #0 #1)) - (the' .private (named_macro' modules current_module module name) (-> ($ Property_List Module) Text Text Text ($ Maybe Macro)) @@ -2754,7 +2784,7 @@ Text) (.when# code {#Bit _ value} - (bit#as value) + (bit#as_text value) {#Natural _ value} (natural#as value) @@ -2912,8 +2942,8 @@ ((normal_type_reification normal_type {#Name @ binding} (list#as_stack parameters)) lux)))) (the' .private (normal_type type' it) - (-> (-> Code ($ Meta Code)) Code - ($ Meta Code)) + (-> (-> Code ($ Meta Code)) + (-> Code ($ Meta Code))) (.when# it {#Variant _ (.list# {#Name _ ["library/lux" "#Named"]} name @@ -2965,6 +2995,11 @@ (meta#let lux [it (monad#each#meta (normal_type type') (list#as_stack it))]) (meta#return lux (` {(,* (list#of_stack it))}))) + {#Tuple _ (.list# {#Bit _ polarity} it)} + (<| (function' (_ lux)) + (meta#let lux [it (normal_type type' it)]) + (meta#return lux (` [(, (code#bit polarity)) (, it)]))) + {#Tuple _ it} (<| (function' (_ lux)) (meta#let lux [it (monad#each#meta (normal_type type') (list#as_stack it))]) @@ -2972,6 +3007,11 @@ {#Form _ binding,parameters} (.when# (list#as_stack binding,parameters) + {#Top {#Name @name ["library/lux" "list#"]} members} + (<| (function' (_ lux)) + (meta#let lux [members (monad#each#meta (normal_type type') members)]) + (meta#return lux (untemplated_list (list#of_stack members)))) + {#Top {#Name @binding binding} parameters} (<| (function' (_ lux)) @@ -3155,7 +3195,7 @@ _ [type (stack)])) -(the' .private (type#as type) +(the' .private (type#as_text type) (-> Type Text) (.when# type @@ -3163,22 +3203,26 @@ (.text_composite# "(Nominal " (text#as name) (|> params - (stack#each (function' (_ it) - (|> it - type#as - (.text_composite# " ")))) + (list#each (function' (_ it) + (.when# it + [polarity it] + (.text_composite# " " + "[" (bit#as_text polarity) + " " (type#as_text it) + "]")))) + list#as_stack stack#reversed (stack#mix text#composite "")) ")") {#Sum _} - (.text_composite# "{" (|> (flat_variant type) (stack#each type#as) (stack#interposed " ") stack#reversed (stack#mix text#composite "")) "}") + (.text_composite# "{" (|> (flat_variant type) (stack#each type#as_text) (stack#interposed " ") stack#reversed (stack#mix text#composite "")) "}") {#Product _} - (.text_composite# "[" (|> (flat_tuple type) (stack#each type#as) (stack#interposed " ") stack#reversed (stack#mix text#composite "")) "]") + (.text_composite# "[" (|> (flat_tuple type) (stack#each type#as_text) (stack#interposed " ") stack#reversed (stack#mix text#composite "")) "]") {#Function _} - (.text_composite# "(-> " (|> (flat_lambda type) (stack#each type#as) (stack#interposed " ") stack#reversed (stack#mix text#composite "")) ")") + (.text_composite# "(-> " (|> (flat_lambda type) (stack#each type#as_text) (stack#interposed " ") stack#reversed (stack#mix text#composite "")) ")") {#Parameter id} (natural#as id) @@ -3190,16 +3234,16 @@ (.text_composite# "+" (natural#as id)) {#Universal env body} - (.text_composite# "(for_any " (type#as body) ")") + (.text_composite# "(for_any " (type#as_text body) ")") {#Existential env body} - (.text_composite# "(for_some " (type#as body) ")") + (.text_composite# "(for_some " (type#as_text body) ")") {#Reification _} (let' [[func args] (flat_reification type)] (.text_composite# - "(" (type#as func) " " - (|> args (stack#each type#as) (stack#interposed " ") stack#reversed (stack#mix text#composite "")) + "(" (type#as_text func) " " + (|> args (stack#each type#as_text) (stack#interposed " ") stack#reversed (stack#mix text#composite "")) ")")) {#Named name _} @@ -3250,7 +3294,7 @@ {#Right [type value]} (.when# (anonymous_type type) - {#Nominal name_of_type {#Empty}} + {#Nominal name_of_type (.list#)} (if (text#= name_of_type (.type_name# "bit")) (in (code#bit (as Bit value))) @@ -3269,7 +3313,7 @@ ... else (failure ..not_a_static_value)) - {#Nominal name_of_type {#Top {#Nominal name_of_specialization {#Empty}} {#Empty}}} + {#Nominal name_of_type (.list# [#1 {#Nominal name_of_specialization (.list#)}])} (if (text#= name_of_type (.type_name# "i64")) (if (text#= name_of_specialization (.type_name# "natural")) (in (code#natural (as Natural value))) @@ -4215,7 +4259,7 @@ _ (failure (.text_composite# "No tags available for type: " - (type#as implementation_type))))) + (type#as_text implementation_type))))) .let [tag_mappings (is (Property_List Code) (list#each (function (_ tag) [(product#right tag) @@ -4912,7 +4956,9 @@ (Change Type)) (when it {#Nominal name parameters} - {#Nominal name (stack#each (clean_type variables) parameters)} + {#Nominal name (list#each (function (_ [parammeter it]) + [parammeter (clean_type variables it)]) + parameters)} {#Sum left right} {#Sum (clean_type variables left) @@ -5084,7 +5130,7 @@ implementation_evidence (record_slots init_type)] (when implementation_evidence {#None} - (failure (.text_composite# "Can only 'open' implementations: " (type#as init_type))) + (failure (.text_composite# "Can only 'open' implementations: " (type#as_text init_type))) {#Some tags,members} (do meta#monad @@ -5222,7 +5268,7 @@ _ (failure (.text_composite# "Can only 'use' implementations: " (name#as implementation) - " : " (type#as interface)))))) + " : " (type#as_text interface)))))) (the (localized module global) (-> Text Name @@ -5593,7 +5639,10 @@ Code) (when type {#Nominal name params} - (` {.#Nominal (, (code#text name)) (, (untemplated_stack (stack#each type_code params)))}) + (` {.#Nominal (, (code#text name)) (, (untemplated_list (list#each (function (_ [polarity it]) + (` [(, (code#bit polarity)) + (, (type_code it))])) + params)))}) (with_template#pattern [] [{ left right} @@ -6156,7 +6205,7 @@ Type (let [[_ proper] (name )] {#Named [..prelude proper] - {.#Nominal (.text_composite# "#Extension/" proper) (stack)}}))] + {.#Nominal (.text_composite# "#Extension/" proper) (list)}}))] [Analysis] [Synthesis] diff --git a/stdlib/source/library/lux/compiler/language/lux/analysis/inference.lux b/stdlib/source/library/lux/compiler/language/lux/analysis/inference.lux index dc86bd645f..1cb81aa746 100644 --- a/stdlib/source/library/lux/compiler/language/lux/analysis/inference.lux +++ b/stdlib/source/library/lux/compiler/language/lux/analysis/inference.lux @@ -64,11 +64,13 @@ ) (the .public (quantified @variable @parameter :it:) - (-> type.Variable Natural Type - Type) + (-> type.Variable Natural + (Change Type)) (`` (when :it: {.#Nominal name co_variant} - {.#Nominal name (stack#each (quantified @variable @parameter) co_variant)} + {.#Nominal name (list#each (function (_ [polarity it]) + [polarity (quantified @variable @parameter it)]) + co_variant)} (,, (template.with [] [{ left right} @@ -215,7 +217,7 @@ (function (again it) (`` (when it (^.or {.#Parameter index} - {.#Reification {.#Nominal "" {.#Empty}} + {.#Reification {.#Nominal "" (list)} {.#Parameter index}}) (if (n.= @self index) recursion @@ -239,7 +241,9 @@ [.#Existential])) {.#Nominal name parameters} - {.#Nominal name (stack#each again parameters)} + {.#Nominal name (list#each (function (_ [polarity it]) + [polarity (again it)]) + parameters)} _ it)))) diff --git a/stdlib/source/library/lux/compiler/language/lux/phase/analysis/when.lux b/stdlib/source/library/lux/compiler/language/lux/phase/analysis/when.lux index 7e2c58ab57..9a772ffa85 100644 --- a/stdlib/source/library/lux/compiler/language/lux/phase/analysis/when.lux +++ b/stdlib/source/library/lux/compiler/language/lux/phase/analysis/when.lux @@ -294,7 +294,7 @@ (do [! phase.monad] [[@ex_var+ type_of_input] (/type.check (..list type_of_input))] (.when type_of_input - {.#Nominal ..name_of_type_of_list (.stack type_of_item)} + {.#Nominal ..name_of_type_of_list (.list [.co_variant type_of_item])} (do ! [[sub_patterns thenA] (stack#mix (is (for_any (_ it) (-> @type.Code (Operation [(Stack Pattern) it]) diff --git a/stdlib/source/library/lux/compiler/language/lux/phase/extension/analysis/jvm.lux b/stdlib/source/library/lux/compiler/language/lux/phase/extension/analysis/jvm.lux index 857b9f6e5c..85af1dd021 100644 --- a/stdlib/source/library/lux/compiler/language/lux/phase/extension/analysis/jvm.lux +++ b/stdlib/source/library/lux/compiler/language/lux/phase/extension/analysis/jvm.lux @@ -225,7 +225,7 @@ (template.with [ ] [(the .public .Type - {.#Nominal {.#Empty}})] + {.#Nominal (list)})] ... Boxes [Boolean box.boolean] @@ -427,7 +427,7 @@ (the lux_array_type (template.macro (_ :read: :write:) - [{.#Nominal array.nominal (stack {.#Reification :write: {.#Reification :read: _Mutable}})}])) + [{.#Nominal array.nominal (list [.co_variant {.#Reification :write: {.#Reification :read: _Mutable}}])}])) (the (jvm_type luxT) (-> .Type (Operation (Type Value))) @@ -450,7 +450,7 @@ (when (dictionary.value class ..boxes) {try.#Success [_ primitive_type]} (when parametersT - {.#Empty} + (list) (phase#in primitive_type) _ @@ -460,7 +460,7 @@ (do [! phase.monad] [parametersJT (is (Operation (List (Type Parameter))) (list.each' ! - (function (_ parameterT) + (function (_ [polarity parameterT]) (do phase.monad [parameterJT (jvm_type parameterT)] (when (projection.parameter? parameterJT) @@ -469,7 +469,7 @@ {.#None} (analysis.except ..non_parameter parameterT)))) - (list.of_stack parametersT)))] + parametersT))] (in (jvm.class parametersJT class)))) {.#Opaque _} @@ -501,7 +501,7 @@ [_ (typeA.inference ..int) arrayA (<| (typeA.expecting {.#Nominal (|> (jvm.array primitive_type) ..reflection) - (stack)}) + (list)}) (analyse archive arrayC)) @ analysis.provenance] (in [@ {analysis.#Extension [.prelude (text extension_name "|translation")] @@ -538,7 +538,7 @@ [lengthA (<| (typeA.expecting ..int) (analyse archive lengthC)) _ (typeA.inference {.#Nominal (|> (jvm.array primitive_type) ..reflection) - (stack)}) + (list)}) @ analysis.provenance] (in [@ {analysis.#Extension [.prelude (text extension_name "|translation")] (list lengthA)}])))])) @@ -631,7 +631,7 @@ (-> .Type (Operation (Type Value))) (`` (when objectT - {.#Nominal name {.#Empty}} + {.#Nominal name (list)} (`` (if (,, (template.with [] [(text.= (..reflection ) name) (phase#in )] @@ -661,7 +661,7 @@ (text.starts_with? descriptor.array_prefix name) (let [[_ unprefixed] (maybe.trusted (text.split_by descriptor.array_prefix name))] (by phase.monad each jvm.array - (check_jvm {.#Nominal unprefixed (stack)}))) + (check_jvm {.#Nominal unprefixed (list)}))) ... else (phase#in (jvm.class (list) name)))) @@ -673,7 +673,7 @@ {.#Nominal name parameters} (do [! phase.monad] - [parameters (list.each' ! check_parameter (list.of_stack parameters))] + [parameters (list.each' ! (|>> product.right check_parameter) parameters)] (phase#in (jvm.class parameters name))) {.#Named name anonymous} @@ -744,7 +744,7 @@ idxA (<| (typeA.expecting ..int) (analyse archive idxC)) arrayA (<| (typeA.expecting {.#Nominal (|> (jvm.array jvm_type) ..reflection) - (stack)}) + (list)}) (analyse archive arrayC)) @ analysis.provenance] (in [@ {analysis.#Extension [.prelude (text extension_name "|translation")] @@ -778,7 +778,7 @@ (-> .Type (Type Primitive) (-> Text Handler)) (let [array_type {.#Nominal (|> (jvm.array jvm_type) ..reflection) - (stack)}] + (list)}] (..custom [(all <>.and ?list.any ?list.any ?list.any) (function (_ extension_name analyse archive [idxC valueC arrayC]) @@ -935,7 +935,7 @@ (function (_ extension_name analyse archive [class]) (do phase.monad [_ (..ensure_fresh_class! class_loader class) - _ (typeA.inference {.#Nominal "java.lang.Class" (stack {.#Nominal class (stack)})}) + _ (typeA.inference {.#Nominal "java.lang.Class" (list [.co_variant {.#Nominal class (list)}])}) _ (phase.of_try (reflection!.load class_loader class)) @ analysis.provenance] (in [@ {analysis.#Extension [.prelude (text extension_name "|translation")] @@ -1383,7 +1383,8 @@ _ (list#composite (list {.#Nominal (ffi.of_string (java/lang/Class::getName [] owner)) - (list.as_stack owner_tvarsT)}) + (list#each (|>> [.co_variant]) + owner_tvarsT)}) inputsT))) outputT)]] (in [#method methodT @@ -1428,7 +1429,8 @@ (phase#each (list.each' ! (reflection_type mapping))) phase#conjoint) .let [objectT {.#Nominal (ffi.of_string (java/lang/Class::getName [] owner)) - (list.as_stack owner_tvarsT)} + (list#each (|>> [.co_variant]) + owner_tvarsT)} constructorT (<| (type.univ_q (dictionary.size mapping)) (type.function inputsT) objectT)]] @@ -2863,7 +2865,7 @@ [where module.current_name id analysis.seed] (in (..anonymous_class_name where id))) - .let [selfT {.#Nominal self_name (stack)}] + .let [selfT {.#Nominal self_name (list)}] mock (<| phase.of_try (..mock [self_name parameters] super_class diff --git a/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/jvm.lux b/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/jvm.lux index c2df21152c..9f51aedf46 100644 --- a/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/jvm.lux +++ b/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/jvm.lux @@ -921,7 +921,9 @@ (dictionary.has (projection.name parameterJ) parameterT mapping)) luxT.fresh parameters) - selfT {.#Nominal name (list.as_stack (list#each product.right parameters))}] + selfT {.#Nominal name (list#each (|>> product.right + [.co_variant]) + parameters)}] state phase.state methods (list.each' ! (let [analysis_state (its [declaration.#analysis declaration.#state] state)] (..method_definition archive super interfaces [mapping selfT] diff --git a/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/lux.lux b/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/lux.lux index 1d02087a89..0b113c162b 100644 --- a/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/lux.lux +++ b/stdlib/source/library/lux/compiler/language/lux/phase/extension/declaration/lux.lux @@ -270,7 +270,9 @@ replacement (`` (when type {.#Nominal name parameters} - {.#Nominal name (stack#each again parameters)} + {.#Nominal name (list#each (function (_ [polarity it]) + [polarity (again it)]) + parameters)} (,, (template.with [] [{ left right} diff --git a/stdlib/source/library/lux/compiler/type.lux b/stdlib/source/library/lux/compiler/type.lux index fad2358f48..13ce5ac1f1 100644 --- a/stdlib/source/library/lux/compiler/type.lux +++ b/stdlib/source/library/lux/compiler/type.lux @@ -3,7 +3,9 @@ (.using [library - [lux (.except Module Name + [lux (.except Polarity contra_variant co_variant + + Module Name Bit Text text Decimal @@ -59,6 +61,18 @@ ["[0]" name]] ["[0]" function]]]) +... https://ncatlab.org/nlab/show/polarity+in+type+theory +(the .public Polarity + .Bit) + +(the contra_variant + Polarity + false) + +(the co_variant + Polarity + true) + (the prefix name.delimiter) @@ -102,7 +116,7 @@ (with_template [,name ,type] [(the .public ,type .Type - {.#Nominal (its #name ,name) (stack)})] + {.#Nominal (its #name ,name) (.list)})] ,each_simple ) @@ -110,7 +124,7 @@ [(the .public ,type .Type (for_any (_ it) - {.#Nominal (its #name ,name) (stack it)}))] + {.#Nominal (its #name ,name) (.list [..co_variant it])}))] ,each_complex ) @@ -118,7 +132,7 @@ [(the .public ,type .Type {.#Nominal (its #name ..i64) - (stack {.#Nominal (its #name ,name) (stack)})})] + (.list [..co_variant {.#Nominal (its #name ,name) (.list)}])})] ,each_integer ) @@ -135,9 +149,9 @@ (the template#macro (.in_module# .prelude .template#macro)) -(the List' - (<| (template#macro (_ ,it)) - [{.#Nominal (its #name ..list) (stack ,it)}])) +(`` (the List' + (<| (template#macro (_ ,it)) + [{.#Nominal (its #name ..list) (.list [(,, (static ..co_variant)) ,it])}]))) ... https://en.wikipedia.org/wiki/Quantifier_(logic) (the Quantification @@ -145,18 +159,6 @@ [[(.Stack ,it) ,it]])) -... https://ncatlab.org/nlab/show/polarity+in+type+theory -(the .public Polarity - ..Bit) - -(the contra_variant - Polarity - false) - -(the co_variant - Polarity - true) - (every .public (Type _) (Variant {#Nominal ..Text (..List' [..Polarity (Type _)])} @@ -174,91 +176,95 @@ (the .public (old it) (-> ..Type .Type) - (`` (when it - {#Nominal name parameters} - {.#Nominal name (|> parameters - (list#each (function (_ [polarity it]) - (old it))) - list.as_stack)} - - (,, (with_template [,new ,old] - [{,new left right} - {,old (old left) (old right)}] - - [#Sum .#Sum] - [#Product .#Product] - [#Function .#Function] - [#Reification .#Reification] - )) - - (,, (with_template [,new ,old] - [{,new it} - {,old it}] - - [#Parameter .#Parameter] - [#Variable .#Variable] - [#Opaque .#Opaque] - )) - - (,, (with_template [,new ,old] - [{,new environment body} - {,old (stack#each old environment) (old body)}] - - [#Universal .#Universal] - [#Existential .#Existential] - )) - - (,, (with_template [,new ,old] - [{,new name body} - {,old name (old body)}] - - [#Named .#Named] - )) - ))) + it + ... (`` (when it + ... {#Nominal name parameters} + ... {.#Nominal name (|> parameters + ... (list#each (function (_ [polarity it]) + ... (old it))) + ... list.as_stack)} + + ... (,, (with_template [,new ,old] + ... [{,new left right} + ... {,old (old left) (old right)}] + + ... [#Sum .#Sum] + ... [#Product .#Product] + ... [#Function .#Function] + ... [#Reification .#Reification] + ... )) + + ... (,, (with_template [,new ,old] + ... [{,new it} + ... {,old it}] + + ... [#Parameter .#Parameter] + ... [#Variable .#Variable] + ... [#Opaque .#Opaque] + ... )) + + ... (,, (with_template [,new ,old] + ... [{,new environment body} + ... {,old (stack#each old environment) (old body)}] + + ... [#Universal .#Universal] + ... [#Existential .#Existential] + ... )) + + ... (,, (with_template [,new ,old] + ... [{,new name body} + ... {,old name (old body)}] + + ... [#Named .#Named] + ... )) + ... )) + ) (the .public (new it) (-> .Type ..Type) - (`` (when it - {.#Nominal name parameters} - {#Nominal name (|> parameters - list.of_stack - (list#each (function (_ it) - [..co_variant (new it)])))} - - (,, (with_template [,new ,old] - [{,old left right} - {,new (new left) (new right)}] - - [#Sum .#Sum] - [#Product .#Product] - [#Function .#Function] - [#Reification .#Reification] - )) - - (,, (with_template [,new ,old] - [{,old it} - {,new it}] - - [#Parameter .#Parameter] - [#Variable .#Variable] - [#Opaque .#Opaque] - )) - - (,, (with_template [,new ,old] - [{,old environment body} - {,new (stack#each new environment) (new body)}] - - [#Universal .#Universal] - [#Existential .#Existential] - )) - - (,, (with_template [,new ,old] - [{,old name body} - {,new name (new body)}] - - [#Named .#Named] - ))))) + it + ... (`` (when it + ... {.#Nominal name parameters} + ... {#Nominal name (|> parameters + ... list.of_stack + ... (list#each (function (_ it) + ... [..co_variant (new it)])))} + + ... (,, (with_template [,new ,old] + ... [{,old left right} + ... {,new (new left) (new right)}] + + ... [#Sum .#Sum] + ... [#Product .#Product] + ... [#Function .#Function] + ... [#Reification .#Reification] + ... )) + + ... (,, (with_template [,new ,old] + ... [{,old it} + ... {,new it}] + + ... [#Parameter .#Parameter] + ... [#Variable .#Variable] + ... [#Opaque .#Opaque] + ... )) + + ... (,, (with_template [,new ,old] + ... [{,old environment body} + ... {,new (stack#each new environment) (new body)}] + + ... [#Universal .#Universal] + ... [#Existential .#Existential] + ... )) + + ... (,, (with_template [,new ,old] + ... [{,old name body} + ... {,new name (new body)}] + + ... [#Named .#Named] + ... )))) + ) (the .public Character .Type @@ -475,18 +481,18 @@ {.#Top head tail} (top (code head) (code#stack code tail)))) -(the (code#argument code it) +(the (code#argument code [polarity it]) (for_any (_ it) (-> (Injection it) - (Injection it))) - (code#tuple (.list (code#bit ..co_variant) + (Injection [Bit it]))) + (code#tuple (.list (code#bit polarity) (code it)))) (the (code#list code it) (for_any (_ it) (-> (Injection it) - (Injection (Stack it)))) - (` (.list# (,* (list#each code (list.of_stack it)))))) + (Injection (List it)))) + (` (.list# (,* (list#each code it))))) (the (code it) (Injection .Type) diff --git a/stdlib/source/library/lux/ffi.jvm.lux b/stdlib/source/library/lux/ffi.jvm.lux index 7d3285238e..fb23099bfa 100644 --- a/stdlib/source/library/lux/ffi.jvm.lux +++ b/stdlib/source/library/lux/ffi.jvm.lux @@ -72,7 +72,7 @@ (template.with [ ] [(`` (the .public .Type - {.#Nominal {.#Empty}}))] + {.#Nominal (list)}))] [Boolean box.boolean] [Byte box.byte] @@ -88,7 +88,7 @@ (template.with [ ] [(`` (the .public .Type - {.#Nominal (reflection.reflection ) {.#Empty}}))] + {.#Nominal (reflection.reflection ) (list)}))] ... Primitives [boolean reflection.boolean] @@ -391,11 +391,14 @@ [projection.upper? limit (parameter_type value_type limit)] [projection.class? [parameters name] (` (.Nominal (, (code.text name)) - [(,* (list#each (parameter_type value_type) parameters))]))] + [(,* (list#each (|>> (parameter_type value_type) + (list (code.bit .co_variant)) + code.tuple) + parameters))]))] [projection.array? elementT (when (projection.primitive? elementT) {.#Some elementT} - (` {.#Nominal (, (code.text (..reflection (jvm.array elementT)))) {.#Empty}}) + (` {.#Nominal (, (code.text (..reflection (jvm.array elementT)))) (.list)}) {.#None} (` (array.Array (, (value_type elementT)))))])) @@ -1425,7 +1428,8 @@ (in (list (` (.jvm_object_null#)))))) (the .public (null? obj) - (-> (.Nominal "java.lang.Object") Bit) + (-> (.Nominal "java.lang.Object") + Bit) (.jvm_object_null?# obj)) (the .public ??? @@ -1493,7 +1497,9 @@ .Type (for_any ((, (' '_)) (,* params')) (.Nominal (, (code.text full_name)) - [(,* params')]))))))) + [(,* (list#each (|>> (list (code.bit .co_variant)) + code.tuple) + params'))]))))))) (the (member_type_vars class_tvars member) (-> (List (Type Var)) Import_Member_Declaration (List (Type Var))) @@ -1688,7 +1694,10 @@ _ (let [=class_tvars (list#each ..var$' class_tvars)] (` (for_any ((, '_) (,* =class_tvars)) - (.Nominal (, (code.text full_name)) [(,* =class_tvars)])))))) + (.Nominal (, (code.text full_name)) + [(,* (list#each (|>> (list (code.bit .co_variant)) + code.tuple) + =class_tvars))])))))) getter_interop (.is (-> Text Code) (function (_ name) (let [getter_name (code.name ["" (..import_name import_format method_prefix name)])] @@ -1845,7 +1854,7 @@ (the interface? (for_any (_ a) - (-> (.Nominal "java.lang.Class" [a]) + (-> (.Nominal "java.lang.Class" [[#1 a]]) Bit)) (|>> (.jvm_member_invoke_virtual# [] "java.lang.Class" "isInterface" []) .jvm_object_cast# @@ -1853,7 +1862,7 @@ (.as Bit))) (the load_class - (-> external.Name (Try (.Nominal "java.lang.Class" [Any]))) + (-> external.Name (Try (.Nominal "java.lang.Class" [[#1 Any]]))) (|>> (.as (.Nominal "java.lang.String")) ["Ljava/lang/String;"] (.jvm_member_invoke_static# [] "java.lang.Class" "forName" []) @@ -1899,7 +1908,7 @@ (`` (if (,, (template.with [] [(text.= (..reflection ) name) (when params - {.#Empty} + (list) (by meta.monad in ) _ @@ -1917,7 +1926,7 @@ (,, (template.with [] [(text.= (..reflection (jvm.array )) name) (when params - {.#Empty} + (list) (by meta.monad in (jvm.array )) _ @@ -1934,7 +1943,7 @@ (text.= array.nominal name) (when params - {.#Top {.#Reification writeLT {.#Reification readLT _Mutable}} {.#Empty}} + (list [.co_variant {.#Reification writeLT {.#Reification readLT _Mutable}}]) (by meta.monad each jvm.array (lux_type->jvm_type context readLT)) @@ -1943,19 +1952,21 @@ (text.starts_with? descriptor.array_prefix name) (when params - {.#Empty} + (list) (let [[_ unprefixed] (maybe.trusted (text.split_by descriptor.array_prefix name))] (by meta.monad each jvm.array - (lux_type->jvm_type context {.#Nominal unprefixed (stack)}))) + (lux_type->jvm_type context {.#Nominal unprefixed (list)}))) _ ) ... else - (by meta.monad each (function (_ parameters) (jvm.class parameters name)) + (by meta.monad each + (function (_ parameters) + (jvm.class parameters name)) (.is (Meta (List (Type Parameter))) (list.each' meta.monad - (function (_ paramLT) + (function (_ [polarity paramLT]) (do meta.monad [paramJT (lux_type->jvm_type context paramLT)] (when (projection.parameter? paramJT) @@ -1964,7 +1975,7 @@ {.#None} ))) - (list.of_stack params)))))) + params))))) {.#Reification A F} (when (type.reified (list A) F) diff --git a/stdlib/source/library/lux/macro/pattern.lux b/stdlib/source/library/lux/macro/pattern.lux index d2d68a268a..b572959771 100644 --- a/stdlib/source/library/lux/macro/pattern.lux +++ b/stdlib/source/library/lux/macro/pattern.lux @@ -48,7 +48,6 @@ [type_definition] [record_slots] [text#composite] - [type#as] [module_alias] [zipped_2] diff --git a/stdlib/source/library/lux/target/jvm/reflection.lux b/stdlib/source/library/lux/target/jvm/reflection.lux index f4fb39ec0a..1888147b5b 100644 --- a/stdlib/source/library/lux/target/jvm/reflection.lux +++ b/stdlib/source/library/lux/target/jvm/reflection.lux @@ -319,7 +319,7 @@ (-> (java/lang/Class java/lang/Object) Type (Try Mapping)) (when type - {.#Nominal array.nominal (stack :member:)} + {.#Nominal array.nominal (list [.co_variant :member:])} (if (ffi.of_boolean (java/lang/Class::isArray [] class)) (correspond (java/lang/Class::getComponentType [] class) :member:) @@ -327,17 +327,16 @@ {.#Nominal name params} (let [class_name (ffi.of_string (java/lang/Class::getName [] class)) - class_params (array.stack {.#None} (java/lang/Class::getTypeParameters [] class)) - num_class_params (stack.size class_params) - num_type_params (stack.size params)] + class_params (list.of_stack (array.stack {.#None} (java/lang/Class::getTypeParameters [] class))) + num_class_params (list.size class_params) + num_type_params (list.size params)] (if (text.= class_name name) (if (n.= num_class_params num_type_params) (|> params - list.of_stack (list.zipped_2 (list#each (|>> (java/lang/reflect/TypeVariable::getName []) ffi.of_string) - (list.of_stack class_params))) - (list#mix (function (_ [name paramT] mapping) + class_params)) + (list#mix (function (_ [name [polarity paramT]] mapping) (dictionary.has name paramT mapping)) /lux.fresh) {try.#Success}) diff --git a/stdlib/source/library/lux/target/jvm/type/lux.lux b/stdlib/source/library/lux/target/jvm/type/lux.lux index 02cb5c3ad3..3197e3d305 100644 --- a/stdlib/source/library/lux/target/jvm/type/lux.lux +++ b/stdlib/source/library/lux/target/jvm/type/lux.lux @@ -17,7 +17,7 @@ ["<[1]>" \\projection (.only Projection)]] [collection ["[0]" array] - ["[0]" list] + ["[0]" list (.use "[1]#[0]" functor)] ["[0]" stack] ["[0]" dictionary (.only Dictionary)]]] [macro @@ -61,7 +61,7 @@ [(the (Projection (Check Type)) (<>.after - (<>#in (check#in {.#Nominal (//reflection.reflection ) {.#Empty}}))))] + (<>#in (check#in {.#Nominal (//reflection.reflection ) (list)}))))] [boolean //projection.boolean //reflection.boolean] [byte //projection.byte //reflection.byte] @@ -77,7 +77,7 @@ [(the (Projection (Check Type)) (<>.after - (<>#in (check#in {.#Nominal {.#Empty}}))))] + (<>#in (check#in {.#Nominal (list)}))))] [boxed_boolean //projection.boolean //box.boolean] [boxed_byte //projection.byte //box.byte] @@ -144,7 +144,7 @@ (<>.else (list)))] (in (do [! check.monad] [parameters (list.all' ! parameters)] - (in {.#Nominal name (list.as_stack parameters)})))) + (in {.#Nominal name (list#each (|>> [.co_variant]) parameters)})))) (<>.after (.this //descriptor.class_prefix)) (<>.before (.this //descriptor.class_suffix)))) @@ -185,7 +185,7 @@ (Projection (Check Type))) (|>> (<>#each (check#each (function (_ elementT) (when elementT - {.#Nominal name {.#Empty}} + {.#Nominal name (list)} (if (`` (or (,, (template.with [] [(text.= (//reflection.reflection ) name)] @@ -197,8 +197,8 @@ [//reflection.float] [//reflection.double] [//reflection.char])))) - {.#Nominal (|> name //reflection.class //reflection.array //reflection.reflection) {.#Empty}} - (|> elementT array.Array .type)) + {.#Nominal (|> name //reflection.class //reflection.array //reflection.reflection) (list)} + (|> elementT array.Array .type)) _ (|> elementT array.Array .type))))) diff --git a/stdlib/source/library/lux/type.lux b/stdlib/source/library/lux/type.lux index c15342e820..587efadce0 100644 --- a/stdlib/source/library/lux/type.lux +++ b/stdlib/source/library/lux/type.lux @@ -17,6 +17,7 @@ ["[0]" predicate (.only Predicate)]] [data ["[0]" product] + ["[0]" bit] ["[0]" text (.only \n) (.use "[1]#[0]" monoid)] [collection ["[0]" array] @@ -111,8 +112,10 @@ (text.enclosed' text.double_quote name) " " (|> params - list.of_stack - (list#each (as_text' name_format)) + (list#each (.function (_ [polarity it]) + (text "[" (bit.as_text polarity) + " " (as_text' name_format it) + "]"))) (text.interposed " ") (text.enclosed ["[" "]"])) ")") @@ -189,7 +192,9 @@ (Change Type)) (when type {.#Nominal name params} - {.#Nominal name (stack#each (reduced env) params)} + {.#Nominal name (list#each (.function (_ [polarity it]) + [polarity (reduced env it)]) + params)} (,, (with_template' [] [{ left right} @@ -236,9 +241,12 @@ false (same? reference it)) (when [reference it] - [{.#Nominal reference_name reference_parameters} {.#Nominal it_name it_parameters}] + [{.#Nominal reference_name reference_parameters} + {.#Nominal it_name it_parameters}] (and (text.= reference_name it_name) - (by (stack.equivalence =) = reference_parameters it_parameters)) + (by (list.equivalence (product.equivalence bit.equivalence =)) = + reference_parameters + it_parameters)) (,, (with_template' [] [[{ reference} { it}] @@ -317,7 +325,10 @@ (when type {.#Nominal name params} (` {.#Nominal (, (code.text name)) - (.stack (,* (list.of_stack (stack#each code params))))}) + (.list (,* (list#each (.function (_ [polarity it]) + (` [(, (code.bit polarity)) + (, (code it))])) + params)))}) (,, (with_template' [] [{ idx} @@ -438,13 +449,14 @@ false))) (the .public (array depth element_type) - (-> Natural Type - Type) + (-> Natural + (Change Type)) (when depth 0 element_type _ (|> element_type (array (-- depth)) - (stack) + [.co_variant] + (list) {.#Nominal array.nominal}))) (the .public (flat_array type) @@ -452,7 +464,7 @@ [Natural Type]) (expansion.let [ [0 type]] (when type - {.#Nominal name (stack element_type)} + {.#Nominal name (list [.co_variant element_type])} (if (text.= array.nominal name) (.let [[depth element_type] (flat_array element_type)] [(++ depth) element_type]) @@ -563,14 +575,16 @@ (.as .Nothing []))))))))) (`` (the .public (replaced before after) - (-> Type Type Type - Type) + (-> Type Type + (Change Type)) (.function (value it) (if (by ..equivalence = before it) after (when it {.#Nominal name co_variant} - {.#Nominal name (stack#each value co_variant)} + {.#Nominal name (list#each (.function (_ [polarity it]) + [polarity (value it)]) + co_variant)} (,, (with_template' [] [{ left right} diff --git a/stdlib/source/library/lux/type/check.lux b/stdlib/source/library/lux/type/check.lux index 10f2424776..2772319d0d 100644 --- a/stdlib/source/library/lux/type/check.lux +++ b/stdlib/source/library/lux/type/check.lux @@ -19,6 +19,7 @@ ["[0]" mixin (.only Mixin)]] [data ["[0]" product] + ["[0]" bit] ["[0]" text (.use "[1]#[0]" monoid)] [collection ["[0]" list (.use "[1]#[0]" monoid)] @@ -562,21 +563,17 @@ (let [[hypotheses super sub] it] (when [super sub] [{.#Nominal e_name e_params} {.#Nominal a_name a_params}] - (if (!text#= e_name a_name) - (loop (again [hypotheses hypotheses - e_params e_params - a_params a_params]) - (when [e_params a_params] - [{.#Empty} {.#Empty}] - (/#in hypotheses) - - [{.#Top e_head e_tail} {.#Top a_head a_tail}] - (do ..monad - [hypotheses' (complete [hypotheses e_head a_head])] - (again hypotheses' e_tail a_tail)) - - _ - ..silent_failure!)) + (if (and (!text#= e_name a_name) + (n.= (list.size e_params) (list.size a_params))) + (list.mix' ..monad + (function (_ [[expected_polarity e_head] + [actual_polarity a_head]] + hypotheses) + (if (bit.= expected_polarity actual_polarity) + (complete [hypotheses e_head a_head]) + ..silent_failure!)) + hypotheses + (list.zipped_2 e_params a_params)) ..silent_failure!) [{.#Opaque e!id} {.#Opaque a!id}] @@ -781,7 +778,10 @@ (`` (when inputT {.#Nominal name paramsT+} (|> paramsT+ - (stack.each' ..monad (clean aliases)) + (list.each' ..monad (function (_ [polarity it]) + (by ..functor each + (|>> [polarity]) + (clean aliases it)))) (/#each (|>> {.#Nominal name}))) (^.or {.#Parameter _} diff --git a/stdlib/source/library/lux/type/nominal.lux b/stdlib/source/library/lux/type/nominal.lux index 8442513d86..100bd90da4 100644 --- a/stdlib/source/library/lux/type/nominal.lux +++ b/stdlib/source/library/lux/type/nominal.lux @@ -101,7 +101,9 @@ (..declaration [full_name type_varsC abstraction_declaration reification_declaration] (` (.these (.every (, export_policy) (, abstraction_declaration) (Nominal (, (code.text (name#as full_name))) - [(,* type_varsC)])) + [(,* (list#each (|>> (list (code.bit .co_variant)) + code.tuple) + type_varsC))])) (.every (, reification_declaration) (, reification_type)) (,* nominals))))))) diff --git a/stdlib/source/library/lux/type/variance.lux b/stdlib/source/library/lux/type/variance.lux index bc593888ae..c1c1300b78 100644 --- a/stdlib/source/library/lux/type/variance.lux +++ b/stdlib/source/library/lux/type/variance.lux @@ -18,7 +18,7 @@ (-> it it)) (every .public (Mutable r w) - (Nominal "#Mutable" [(-> w r)])) + (Nominal "#Mutable" [[#1 (-> w r)]])) (with_template' [ ] [(the .public diff --git a/stdlib/source/projection/lux/data/binary.lux b/stdlib/source/projection/lux/data/binary.lux index eb8a7216e0..f9ed650145 100644 --- a/stdlib/source/projection/lux/data/binary.lux +++ b/stdlib/source/projection/lux/data/binary.lux @@ -314,7 +314,7 @@ (let [pair (//.and type type) indexed ..natural quantified (//.and (..stack type) type)] - (!variant [[00 [.#Nominal] (//.and ..text (..stack type))] + (!variant [[00 [.#Nominal] (//.and ..text (..list (//.and bit type)))] [01 [.#Sum] pair] [02 [.#Product] pair] [03 [.#Function] pair] diff --git a/stdlib/source/projection/lux/type.lux b/stdlib/source/projection/lux/type.lux index 77fc2cd5fe..367d348ddb 100644 --- a/stdlib/source/projection/lux/type.lux +++ b/stdlib/source/projection/lux/type.lux @@ -31,7 +31,7 @@ (the .public recursion_parameter (template.macro (_) - [{.#Nominal "" {.#Empty}}])) + [{.#Nominal "" (.list)}])) (the .public recursive_definition (template.macro (_ ,type) diff --git a/stdlib/source/unsafe/lux/data/collection/array.lux b/stdlib/source/unsafe/lux/data/collection/array.lux index e3d99d53b4..3f1cf8549f 100644 --- a/stdlib/source/unsafe/lux/data/collection/array.lux +++ b/stdlib/source/unsafe/lux/data/collection/array.lux @@ -28,7 +28,7 @@ (with_template' [ ] [(.every .public - {.#Nominal ..nominal {.#Top {.#Empty}}})] + {.#Nominal ..nominal (list [#1 ])})] [(variance.Mutable read write) (Array' read write)] [(variance.Mutable it it) (Array it)] @@ -122,26 +122,26 @@ (.function (lacks? index array) (.let [size (..size array)] (.if (.int_<# (.integer size) (.integer index)) - (.for .jvm - (.|> array - (.jvm_array_read_object# (,, (jvm_integer index))) - .jvm_object_null?#) - - .js - (,, (lacks?' .js_array_read# .js_object_undefined?# index array)) - - .python - (,, (lacks?' .python_array_read# .python_object_none?# index array)) - - .lua - (,, (lacks?' .lua_array_read# .lua_object_nil?# index array)) - - .ruby - (,, (lacks?' .ruby_array_read# .ruby_object_nil?# index array)) - - .php - (,, (lacks?' "php array read" "php object null?" index array))) - .true)))) + (.for .jvm + (.|> array + (.jvm_array_read_object# (,, (jvm_integer index))) + .jvm_object_null?#) + + .js + (,, (lacks?' .js_array_read# .js_object_undefined?# index array)) + + .python + (,, (lacks?' .python_array_read# .python_object_none?# index array)) + + .lua + (,, (lacks?' .lua_array_read# .lua_object_nil?# index array)) + + .ruby + (,, (lacks?' .ruby_array_read# .ruby_object_nil?# index array)) + + .php + (,, (lacks?' "php array read" "php object null?" index array))) + .true)))) )]))) (the .public has? @@ -213,24 +213,24 @@ (.function (lacks! index array) (.let [size (..size array)] (.if (.int_<# (.integer size) (.integer index)) - (.for .jvm - (..has! index (.as_expected (is (.jvm_object_null#))) array) - - .js - (.js_array_delete# index array) - - .python - (.python_array_delete# index array) - - .lua - (.lua_array_delete# index array) - - .ruby - (.ruby_array_delete# index array) - - .php - ("php array delete" index array)) - array)))) + (.for .jvm + (..has! index (.as_expected (is (.jvm_object_null#))) array) + + .js + (.js_array_delete# index array) + + .python + (.python_array_delete# index array) + + .lua + (.lua_array_delete# index array) + + .ruby + (.ruby_array_delete# index array) + + .php + ("php array delete" index array)) + array)))) )])))) ) @@ -242,8 +242,8 @@ (..Array' read write))) (.function (revised! index $ array) (.if (..lacks? index array) - array - (..has! index ($ (..item index array)) array)))) + array + (..has! index ($ (..item index array)) array)))) <$> )])) (the .public upsert! @@ -255,8 +255,8 @@ (.function (upsert! index default $ array) (..has! index ($ (.if (..lacks? index array) - default - (..item index array))) + default + (..item index array))) array))) <$> )])) @@ -298,14 +298,14 @@ ... else (.loop (again [offset 0]) (.if (.int_<# (.integer length) (.integer offset)) - (.exec - (.if (..lacks? (.i64_+# offset src_start) src_array) - (..lacks! (.i64_+# offset dest_start) dest_array) - (..has! (.i64_+# offset dest_start) - (..item (.i64_+# offset src_start) src_array) - dest_array)) - (again (.i64_+# 1 offset))) - dest_array))))) + (.exec + (.if (..lacks? (.i64_+# offset src_start) src_array) + (..lacks! (.i64_+# offset dest_start) dest_array) + (..has! (.i64_+# offset dest_start) + (..item (.i64_+# offset src_start) src_array) + dest_array)) + (again (.i64_+# 1 offset))) + dest_array))))) )]))) (with_template' [ ] @@ -320,10 +320,10 @@ (.loop (again [index 0 it 0]) (.if (.int_<# (.integer size) (.integer index)) - (.if (..lacks? index array) - (again (.i64_+# 1 index) ) - (again (.i64_+# 1 index) )) - it))))) + (.if (..lacks? index array) + (again (.i64_+# 1 index) ) + (again (.i64_+# 1 index) )) + it))))) )]))] [occupancy it (.i64_+# 1 it)] @@ -340,14 +340,14 @@ (.let [size (..size it)] (.loop (again [index 0]) (.if (.int_<# (.integer size) (.integer index)) - (.exec - (.if (..lacks? index it) - it - (.if (? (..item index it)) - it - (..lacks! index it))) - (again (.i64_+# 1 index))) - it))))) + (.exec + (.if (..lacks? index it) + it + (.if (? (..item index it)) + it + (..lacks! index it))) + (again (.i64_+# 1 index))) + it))))) )])) (the .public no_example @@ -366,13 +366,13 @@ (.let [size (..size it)] (.loop (again [index 0]) (.if (.int_<# (.integer size) (.integer index)) - (.if (..lacks? index it) - (again (.i64_+# 1 index)) - (.let [it (..item index it)] - (.if - {try.#Success } - (again (.i64_+# 1 index))))) - {try.#Failure ..no_example}))))) + (.if (..lacks? index it) + (again (.i64_+# 1 index)) + (.let [it (..item index it)] + (.if + {try.#Success } + (again (.i64_+# 1 index))))) + {try.#Failure ..no_example}))))) )]))] [example (.-> read .Bit) (? it) read it] @@ -425,11 +425,11 @@ (.loop (again [index (.i64_-# 1 (..size array)) output empty]) (.if (.i64_=# (,, (.static ..underflow)) index) - output - (again (.i64_-# 1 index) - (.if (..lacks? index array) - output - {.#Top (..item index array) output})))))) + output + (again (.i64_-# 1 index) + (.if (..lacks? index array) + output + {.#Top (..item index array) output})))))) )]))) (`` (the stack|+default @@ -443,12 +443,12 @@ output (`` (.is (.Stack (,, (.these (,, (.type_of default))))) {.#Empty}))]) (.if (.i64_=# (,, (.static ..underflow)) index) - output - (again (.i64_-# 1 index) - {.#Top (.if (..lacks? index array) - default - (..item index array)) - output}))))) + output + (again (.i64_-# 1 index) + {.#Top (.if (..lacks? index array) + default + (..item index array)) + output}))))) )]))) (`` (the .public stack @@ -478,14 +478,14 @@ (.and (.i64_=# (..size right/*) size) (.loop (again [index 0]) (.if (.int_<# (.integer size) (.integer index)) - (.if (..lacks? index left/*) - (..lacks? index right/*) - (.if (..lacks? index right/*) - .false - (.and (//#= (..item index left/*) - (..item index right/*)) - (again (.i64_+# 1 index))))) - true)))))) + (.if (..lacks? index left/*) + (..lacks? index right/*) + (.if (..lacks? index right/*) + .false + (.and (//#= (..item index left/*) + (..item index right/*)) + (again (.i64_+# 1 index))))) + true)))))) )])) (the .public composite @@ -513,10 +513,10 @@ (.loop (again [index 0 so_far init]) (.if (.int_<# (.integer size) (.integer index)) - (.if (..lacks? index it) - (again (.i64_+# 1 index) so_far) - (again (.i64_+# 1 index) ($ index (..item index it) so_far))) - so_far))))) + (.if (..lacks? index it) + (again (.i64_+# 1 index) so_far) + (again (.i64_+# 1 index) ($ index (..item index it) so_far))) + so_far))))) <$> )])) (the .public each @@ -541,11 +541,11 @@ (.let [size (..size it)] (.loop (again [index 0]) (.if (.int_<# (.integer size) (.integer index)) - (.if (..lacks? index it) - (again (.i64_+# 1 index)) - ( (? (..item index it)) - (again (.i64_+# 1 index)))) - ))))) + (.if (..lacks? index it) + (again (.i64_+# 1 index)) + ( (? (..item index it)) + (again (.i64_+# 1 index)))) + ))))) )]))] [every? .true and] @@ -567,14 +567,14 @@ (.let [size (..size it)] (.loop (again [index 0]) (.if (.int_<# (.integer size) (.integer index)) - (<| (.._expansion#let [ (again (.i64_+# 1 index))]) - (.if (..lacks? index it) - - (.when (? (..item index it)) - {.#None} - - - {.#Some output} - {try.#Success output}))) - {try.#Failure ..no_one}))))) + (<| (.._expansion#let [ (again (.i64_+# 1 index))]) + (.if (..lacks? index it) + + (.when (? (..item index it)) + {.#None} + + + {.#Some output} + {try.#Success output}))) + {try.#Failure ..no_one}))))) )]))