diff options
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/type.lux | 86 |
1 files changed, 47 insertions, 39 deletions
diff --git a/stdlib/source/library/lux/type.lux b/stdlib/source/library/lux/type.lux index 55fa0b166..8e7541755 100644 --- a/stdlib/source/library/lux/type.lux +++ b/stdlib/source/library/lux/type.lux @@ -1,6 +1,6 @@ (.using [library - [lux {"-" function :as} + [lux {"-" function as let} ["@" target] [abstract [equivalence {"+" Equivalence}] @@ -16,7 +16,7 @@ ["[0]" text ("[1]#[0]" monoid equivalence)] [collection ["[0]" array] - ["[0]" list ("[1]#[0]" functor monoid mix)]]] + ["[0]" list ("[1]#[0]" monad monoid mix)]]] ["[0]" macro [syntax {"+" syntax:}] ["^" pattern] @@ -48,7 +48,7 @@ (-> Type [(List Type) Type]) (case type {.#Function in out'} - (let [[ins out] (flat_function out')] + (.let [[ins out] (flat_function out')] [(list& in ins) out]) _ @@ -58,7 +58,7 @@ (-> Type [Type (List Type)]) (case type {.#Apply arg func'} - (let [[func args] (flat_application func')] + (.let [[func args] (flat_application func')] [func (list#composite args (list arg))]) _ @@ -103,7 +103,7 @@ [.#Product "[" "]" flat_tuple]) {.#Function input output} - (let [[ins out] (flat_function type)] + (.let [[ins out] (flat_function type)] ($_ text#composite "(-> " (|> ins (list#each format) @@ -122,7 +122,7 @@ ($_ text#composite "+" (n#encoded id)) {.#Apply param fun} - (let [[type_func type_args] (flat_application type)] + (.let [[type_func type_args] (flat_application type)] ($_ text#composite "(" (format type_func) " " (|> type_args (list#each format) list.reversed (list.interposed " ") (list#mix text#composite "")) ")")) (^.template [<tag> <desc>] @@ -370,7 +370,7 @@ (case type (^.multi (pattern {.#Primitive name (list element_type)}) (text#= array.type_name name)) - (let [[depth element_type] (flat_array element_type)] + (.let [[depth element_type] (flat_array element_type)] [(++ depth) element_type]) _ @@ -389,9 +389,9 @@ (def: secret_marker (`` (symbol (~~ (new_secret_marker))))) -(syntax: .public (:log! [input (<>.or (<>.and <code>.symbol - (<>.maybe (<>.after (<code>.symbol! ..secret_marker) <code>.any))) - <code>.any)]) +(syntax: .public (log! [input (<>.or (<>.and <code>.symbol + (<>.maybe (<>.after (<code>.symbol! ..secret_marker) <code>.any))) + <code>.any)]) (case input {.#Left [valueN valueC]} (do meta.monad @@ -399,7 +399,7 @@ valueT (meta.type valueN) .let [_ ("lux io log" ($_ text#composite - (symbol#encoded (symbol ..:log!)) " " (location.format location) text.new_line + (symbol#encoded (symbol ..log!)) " " (location.format location) text.new_line "Expression: " (case valueC {.#Some valueC} (code.format valueC) @@ -413,20 +413,20 @@ {.#Right valueC} (macro.with_symbols [g!value] (in (list (` (.let [(~ g!value) (~ valueC)] - (..:log! (~ valueC) (~ (code.symbol ..secret_marker)) (~ g!value))))))))) + (..log! (~ valueC) (~ (code.symbol ..secret_marker)) (~ g!value))))))))) (def: type_parameters (Parser (List Text)) (<code>.tuple (<>.some <code>.local_symbol))) -(syntax: .public (:as [type_vars type_parameters - input <code>.any - output <code>.any - value (<>.maybe <code>.any)]) +(syntax: .public (as [type_vars type_parameters + input <code>.any + output <code>.any + value (<>.maybe <code>.any)]) (macro.with_symbols [g!_] - (let [casterC (` (: (All ((~ g!_) (~+ (list#each code.local_symbol type_vars))) - (-> (~ input) (~ output))) - (|>> :expected)))] + (.let [casterC (` (is (All ((~ g!_) (~+ (list#each code.local_symbol type_vars))) + (-> (~ input) (~ output))) + (|>> as_expected)))] (case value {.#None} (in (list casterC)) @@ -444,30 +444,30 @@ (<>.and <code>.any <code>.any)) ... TODO: Make sure the generated code always gets optimized away. -(syntax: .public (:sharing [type_vars ..type_parameters - exemplar ..typed - computation ..typed]) +(syntax: .public (sharing [type_vars ..type_parameters + exemplar ..typed + computation ..typed]) (macro.with_symbols [g!_] - (let [typeC (` (All ((~ g!_) (~+ (list#each code.local_symbol type_vars))) - (-> (~ (the #type exemplar)) - (~ (the #type computation))))) - shareC (` (: (~ typeC) - (.function ((~ g!_) (~ g!_)) - (~ (the #expression computation)))))] + (.let [typeC (` (All ((~ g!_) (~+ (list#each code.local_symbol type_vars))) + (-> (~ (the #type exemplar)) + (~ (the #type computation))))) + shareC (` (is (~ typeC) + (.function ((~ g!_) (~ g!_)) + (~ (the #expression computation)))))] (in (list (` ((~ shareC) (~ (the #expression exemplar))))))))) -(syntax: .public (:by_example [type_vars ..type_parameters - exemplar ..typed - extraction <code>.any]) - (in (list (` (:of ((~! ..:sharing) - [(~+ (list#each code.local_symbol type_vars))] +(syntax: .public (by_example [type_vars ..type_parameters + exemplar ..typed + extraction <code>.any]) + (in (list (` (.type_of ((~! ..sharing) + [(~+ (list#each code.local_symbol type_vars))] - (~ (the #type exemplar)) - (~ (the #expression exemplar)) - - (~ extraction) - ... The value of this expression will never be relevant, so it doesn't matter what it is. - (.:as .Nothing []))))))) + (~ (the #type exemplar)) + (~ (the #expression exemplar)) + + (~ extraction) + ... The value of this expression will never be relevant, so it doesn't matter what it is. + (.as .Nothing []))))))) (def: .public (replaced before after) (-> Type Type Type Type) @@ -497,3 +497,11 @@ {.#Ex _} {.#Named _}) it)))) + +(syntax: .public (let [bindings (<code>.tuple (<>.some (<>.and <code>.any <code>.any))) + bodyT <code>.any]) + (in (list (` (..with_expansions [(~+ (|> bindings + (list#each (.function (_ [localT valueT]) + (list localT (` (..as_is (~ valueT)))))) + list#conjoint))] + (~ bodyT)))))) |