diff options
Diffstat (limited to 'stdlib/source/poly')
-rw-r--r-- | stdlib/source/poly/lux/abstract/equivalence.lux | 228 | ||||
-rw-r--r-- | stdlib/source/poly/lux/abstract/functor.lux | 114 | ||||
-rw-r--r-- | stdlib/source/poly/lux/data/format/json.lux | 318 |
3 files changed, 330 insertions, 330 deletions
diff --git a/stdlib/source/poly/lux/abstract/equivalence.lux b/stdlib/source/poly/lux/abstract/equivalence.lux index 79c85032a..1e95ec091 100644 --- a/stdlib/source/poly/lux/abstract/equivalence.lux +++ b/stdlib/source/poly/lux/abstract/equivalence.lux @@ -49,120 +49,120 @@ .let [@Equivalence (is (-> Type Code) (function (_ type) (` ((~! /.Equivalence) (~ (poly.code *env* type))))))]] - ($_ <>.either - ... Basic types - (~~ (template [<matcher> <eq>] - [(do ! - [_ <matcher>] - (in (` (is (~ (@Equivalence inputT)) - <eq>))))] + (all <>.either + ... Basic types + (~~ (template [<matcher> <eq>] + [(do ! + [_ <matcher>] + (in (` (is (~ (@Equivalence inputT)) + <eq>))))] - [(<type>.exactly Any) (function ((~ g!_) (~ g!_) (~ g!_)) #1)] - [(<type>.sub Bit) (~! bit.equivalence)] - [(<type>.sub Nat) (~! nat.equivalence)] - [(<type>.sub Int) (~! int.equivalence)] - [(<type>.sub Rev) (~! rev.equivalence)] - [(<type>.sub Frac) (~! frac.equivalence)] - [(<type>.sub Text) (~! text.equivalence)])) - ... Composite types - (~~ (template [<name> <eq>] - [(do ! - [[_ argC] (<type>.applied (<>.and (<type>.exactly <name>) - equivalence))] - (in (` (is (~ (@Equivalence inputT)) - (<eq> (~ argC))))))] + [(<type>.exactly Any) (function ((~ g!_) (~ g!_) (~ g!_)) #1)] + [(<type>.sub Bit) (~! bit.equivalence)] + [(<type>.sub Nat) (~! nat.equivalence)] + [(<type>.sub Int) (~! int.equivalence)] + [(<type>.sub Rev) (~! rev.equivalence)] + [(<type>.sub Frac) (~! frac.equivalence)] + [(<type>.sub Text) (~! text.equivalence)])) + ... Composite types + (~~ (template [<name> <eq>] + [(do ! + [[_ argC] (<type>.applied (<>.and (<type>.exactly <name>) + equivalence))] + (in (` (is (~ (@Equivalence inputT)) + (<eq> (~ argC))))))] - [.Maybe (~! maybe.equivalence)] - [.List (~! list.equivalence)] - [sequence.Sequence (~! sequence.equivalence)] - [array.Array (~! array.equivalence)] - [queue.Queue (~! queue.equivalence)] - [set.Set (~! set.equivalence)] - [tree.Tree (~! tree.equivalence)] - )) - (do ! - [[_ _ valC] (<type>.applied ($_ <>.and - (<type>.exactly dictionary.Dictionary) - <type>.any - equivalence))] - (in (` (is (~ (@Equivalence inputT)) - ((~! dictionary.equivalence) (~ valC)))))) - ... Models - (~~ (template [<type> <eq>] - [(do ! - [_ (<type>.exactly <type>)] - (in (` (is (~ (@Equivalence inputT)) - <eq>))))] + [.Maybe (~! maybe.equivalence)] + [.List (~! list.equivalence)] + [sequence.Sequence (~! sequence.equivalence)] + [array.Array (~! array.equivalence)] + [queue.Queue (~! queue.equivalence)] + [set.Set (~! set.equivalence)] + [tree.Tree (~! tree.equivalence)] + )) + (do ! + [[_ _ valC] (<type>.applied (all <>.and + (<type>.exactly dictionary.Dictionary) + <type>.any + equivalence))] + (in (` (is (~ (@Equivalence inputT)) + ((~! dictionary.equivalence) (~ valC)))))) + ... Models + (~~ (template [<type> <eq>] + [(do ! + [_ (<type>.exactly <type>)] + (in (` (is (~ (@Equivalence inputT)) + <eq>))))] - [duration.Duration duration.equivalence] - [instant.Instant instant.equivalence] - [date.Date date.equivalence] - [day.Day day.equivalence] - [month.Month month.equivalence] - )) - (do ! - [_ (<type>.applied (<>.and (<type>.exactly unit.Qty) - <type>.any))] - (in (` (is (~ (@Equivalence inputT)) - unit.equivalence)))) - ... Variants - (do ! - [members (<type>.variant (<>.many equivalence)) - .let [last (-- (list.size members)) - g!_ (code.local "_____________") - g!left (code.local "_____________left") - g!right (code.local "_____________right")]] - (in (` (is (~ (@Equivalence inputT)) - (function ((~ g!_) (~ g!left) (~ g!right)) - (case [(~ g!left) (~ g!right)] - (~+ (list#conjoint (list#each (function (_ [tag g!eq]) - (if (nat.= last tag) - (list (` [{(~ (code.nat (-- tag))) #1 (~ g!left)} - {(~ (code.nat (-- tag))) #1 (~ g!right)}]) - (` ((~ g!eq) (~ g!left) (~ g!right)))) - (list (` [{(~ (code.nat tag)) #0 (~ g!left)} - {(~ (code.nat tag)) #0 (~ g!right)}]) - (` ((~ g!eq) (~ g!left) (~ g!right)))))) - (list.enumeration members)))) - (~ g!_) - #0)))))) - ... Tuples - (do ! - [g!eqs (<type>.tuple (<>.many equivalence)) - .let [g!_ (code.local "_____________") - indices (list.indices (list.size g!eqs)) - g!lefts (list#each (|>> nat#encoded (text#composite "left") code.local) indices) - g!rights (list#each (|>> nat#encoded (text#composite "right") code.local) indices)]] - (in (` (is (~ (@Equivalence inputT)) - (function ((~ g!_) [(~+ g!lefts)] [(~+ g!rights)]) - (and (~+ (|> (list.zipped_3 g!eqs g!lefts g!rights) - (list#each (function (_ [g!eq g!left g!right]) - (` ((~ g!eq) (~ g!left) (~ g!right))))))))))))) - ... Type recursion - (do ! - [[g!self bodyC] (<type>.recursive equivalence) - .let [g!_ (code.local "_____________")]] - (in (` (is (~ (@Equivalence inputT)) - ((~! /.rec) (.function ((~ g!_) (~ g!self)) - (~ bodyC))))))) - <type>.recursive_self - ... Type applications - (do ! - [[funcC argsC] (<type>.applied (<>.and equivalence (<>.many equivalence)))] - (in (` ((~ funcC) (~+ argsC))))) - ... Parameters - <type>.parameter - ... Polymorphism - (do ! - [[funcC varsC bodyC] (<type>.polymorphic equivalence)] - (in (` (is (All ((~ g!_) (~+ varsC)) - (-> (~+ (list#each (|>> (~) ((~! /.Equivalence)) (`)) varsC)) - ((~! /.Equivalence) ((~ (poly.code *env* inputT)) (~+ varsC))))) - (function ((~ funcC) (~+ varsC)) - (~ bodyC)))))) - <type>.recursive_call - ... If all else fails... - (|> <type>.any - (# ! each (|>> %.type (format "Cannot create Equivalence for: ") <>.failure)) - (# ! conjoint)) - )))) + [duration.Duration duration.equivalence] + [instant.Instant instant.equivalence] + [date.Date date.equivalence] + [day.Day day.equivalence] + [month.Month month.equivalence] + )) + (do ! + [_ (<type>.applied (<>.and (<type>.exactly unit.Qty) + <type>.any))] + (in (` (is (~ (@Equivalence inputT)) + unit.equivalence)))) + ... Variants + (do ! + [members (<type>.variant (<>.many equivalence)) + .let [last (-- (list.size members)) + g!_ (code.local "_____________") + g!left (code.local "_____________left") + g!right (code.local "_____________right")]] + (in (` (is (~ (@Equivalence inputT)) + (function ((~ g!_) (~ g!left) (~ g!right)) + (case [(~ g!left) (~ g!right)] + (~+ (list#conjoint (list#each (function (_ [tag g!eq]) + (if (nat.= last tag) + (list (` [{(~ (code.nat (-- tag))) #1 (~ g!left)} + {(~ (code.nat (-- tag))) #1 (~ g!right)}]) + (` ((~ g!eq) (~ g!left) (~ g!right)))) + (list (` [{(~ (code.nat tag)) #0 (~ g!left)} + {(~ (code.nat tag)) #0 (~ g!right)}]) + (` ((~ g!eq) (~ g!left) (~ g!right)))))) + (list.enumeration members)))) + (~ g!_) + #0)))))) + ... Tuples + (do ! + [g!eqs (<type>.tuple (<>.many equivalence)) + .let [g!_ (code.local "_____________") + indices (list.indices (list.size g!eqs)) + g!lefts (list#each (|>> nat#encoded (text#composite "left") code.local) indices) + g!rights (list#each (|>> nat#encoded (text#composite "right") code.local) indices)]] + (in (` (is (~ (@Equivalence inputT)) + (function ((~ g!_) [(~+ g!lefts)] [(~+ g!rights)]) + (and (~+ (|> (list.zipped_3 g!eqs g!lefts g!rights) + (list#each (function (_ [g!eq g!left g!right]) + (` ((~ g!eq) (~ g!left) (~ g!right))))))))))))) + ... Type recursion + (do ! + [[g!self bodyC] (<type>.recursive equivalence) + .let [g!_ (code.local "_____________")]] + (in (` (is (~ (@Equivalence inputT)) + ((~! /.rec) (.function ((~ g!_) (~ g!self)) + (~ bodyC))))))) + <type>.recursive_self + ... Type applications + (do ! + [[funcC argsC] (<type>.applied (<>.and equivalence (<>.many equivalence)))] + (in (` ((~ funcC) (~+ argsC))))) + ... Parameters + <type>.parameter + ... Polymorphism + (do ! + [[funcC varsC bodyC] (<type>.polymorphic equivalence)] + (in (` (is (All ((~ g!_) (~+ varsC)) + (-> (~+ (list#each (|>> (~) ((~! /.Equivalence)) (`)) varsC)) + ((~! /.Equivalence) ((~ (poly.code *env* inputT)) (~+ varsC))))) + (function ((~ funcC) (~+ varsC)) + (~ bodyC)))))) + <type>.recursive_call + ... If all else fails... + (|> <type>.any + (# ! each (|>> %.type (format "Cannot create Equivalence for: ") <>.failure)) + (# ! conjoint)) + )))) diff --git a/stdlib/source/poly/lux/abstract/functor.lux b/stdlib/source/poly/lux/abstract/functor.lux index 80f8d414a..97c900493 100644 --- a/stdlib/source/poly/lux/abstract/functor.lux +++ b/stdlib/source/poly/lux/abstract/functor.lux @@ -44,63 +44,63 @@ ((~! /.Functor) ((~ (poly.code *env* unwrappedT)) (~+ paramsC))))))))) Arg<?> (is (-> Code (<type>.Parser Code)) (function (Arg<?> valueC) - ($_ p.either - ... Type-var - (do p.monad - [.let [varI (|> num_vars (n.* 2) --)] - _ (<type>.this_parameter varI)] - (in (` ((~ funcC) (~ valueC))))) - ... Variants - (do ! - [_ (in []) - membersC (<type>.variant (p.many (Arg<?> valueC))) - .let [last (-- (list.size membersC))]] - (in (` (case (~ valueC) - (~+ (list#conjoint (list#each (function (_ [tag memberC]) - (if (n.= last tag) - (list (` {(~ (code.nat (-- tag))) #1 (~ valueC)}) - (` {(~ (code.nat (-- tag))) #1 (~ memberC)})) - (list (` {(~ (code.nat tag)) #0 (~ valueC)}) - (` {(~ (code.nat tag)) #0 (~ memberC)})))) - (list.enumeration membersC)))))))) - ... Tuples - (do p.monad - [pairsCC (is (<type>.Parser (List [Code Code])) - (<type>.tuple (loop (again [idx 0 - pairsCC (is (List [Code Code]) - (list))]) - (p.either (let [slotC (|> idx %.nat (format "____________slot") code.local)] - (do ! - [_ (in []) - memberC (Arg<?> slotC)] - (again (++ idx) - (list#composite pairsCC (list [slotC memberC]))))) - (in pairsCC)))))] - (in (` (case (~ valueC) - [(~+ (list#each product.left pairsCC))] - [(~+ (list#each product.right pairsCC))])))) - ... Functions - (do ! - [_ (in []) - .let [g! (code.local "____________") - outL (code.local "____________outL")] - [inT+ outC] (<type>.function (p.many <type>.any) - (Arg<?> outL)) - .let [inC+ (|> (list.size inT+) - list.indices - (list#each (|>> %.nat (format "____________inC") code.local)))]] - (in (` (function ((~ g!) (~+ inC+)) - (let [(~ outL) ((~ valueC) (~+ inC+))] - (~ outC)))))) - ... Recursion - (do p.monad - [_ <type>.recursive_call] - (in (` ((~' each) (~ funcC) (~ valueC))))) - ... Parameters - (do p.monad - [_ <type>.any] - (in valueC)) - )))] + (all p.either + ... Type-var + (do p.monad + [.let [varI (|> num_vars (n.* 2) --)] + _ (<type>.this_parameter varI)] + (in (` ((~ funcC) (~ valueC))))) + ... Variants + (do ! + [_ (in []) + membersC (<type>.variant (p.many (Arg<?> valueC))) + .let [last (-- (list.size membersC))]] + (in (` (case (~ valueC) + (~+ (list#conjoint (list#each (function (_ [tag memberC]) + (if (n.= last tag) + (list (` {(~ (code.nat (-- tag))) #1 (~ valueC)}) + (` {(~ (code.nat (-- tag))) #1 (~ memberC)})) + (list (` {(~ (code.nat tag)) #0 (~ valueC)}) + (` {(~ (code.nat tag)) #0 (~ memberC)})))) + (list.enumeration membersC)))))))) + ... Tuples + (do p.monad + [pairsCC (is (<type>.Parser (List [Code Code])) + (<type>.tuple (loop (again [idx 0 + pairsCC (is (List [Code Code]) + (list))]) + (p.either (let [slotC (|> idx %.nat (format "____________slot") code.local)] + (do ! + [_ (in []) + memberC (Arg<?> slotC)] + (again (++ idx) + (list#composite pairsCC (list [slotC memberC]))))) + (in pairsCC)))))] + (in (` (case (~ valueC) + [(~+ (list#each product.left pairsCC))] + [(~+ (list#each product.right pairsCC))])))) + ... Functions + (do ! + [_ (in []) + .let [g! (code.local "____________") + outL (code.local "____________outL")] + [inT+ outC] (<type>.function (p.many <type>.any) + (Arg<?> outL)) + .let [inC+ (|> (list.size inT+) + list.indices + (list#each (|>> %.nat (format "____________inC") code.local)))]] + (in (` (function ((~ g!) (~+ inC+)) + (let [(~ outL) ((~ valueC) (~+ inC+))] + (~ outC)))))) + ... Recursion + (do p.monad + [_ <type>.recursive_call] + (in (` ((~' each) (~ funcC) (~ valueC))))) + ... Parameters + (do p.monad + [_ <type>.any] + (in valueC)) + )))] [_ _ outputC] (is (<type>.Parser [Code (List Code) Code]) (p.either (<type>.polymorphic (Arg<?> inputC)) diff --git a/stdlib/source/poly/lux/data/format/json.lux b/stdlib/source/poly/lux/data/format/json.lux index e838c73b4..9e4a6a369 100644 --- a/stdlib/source/poly/lux/data/format/json.lux +++ b/stdlib/source/poly/lux/data/format/json.lux @@ -129,97 +129,97 @@ (function (_ type) (` (-> (~ (poly.code *env* type)) /.JSON))))] inputT <type>.next] - ($_ <>.either - <basic> - <time> - (do ! - [unitT (<type>.applied (<>.after (<type>.exactly unit.Qty) - <type>.any))] - (in (` (is (~ (@JSON#encoded inputT)) - (# (~! qty_codec) (~' encoded)))))) - (do ! - [.let [g!_ (code.local "_______") - g!key (code.local "_______key") - g!val (code.local "_______val")] - [_ _ =val=] (<type>.applied ($_ <>.and - (<type>.exactly dictionary.Dictionary) - (<type>.exactly .Text) + (all <>.either + <basic> + <time> + (do ! + [unitT (<type>.applied (<>.after (<type>.exactly unit.Qty) + <type>.any))] + (in (` (is (~ (@JSON#encoded inputT)) + (# (~! qty_codec) (~' encoded)))))) + (do ! + [.let [g!_ (code.local "_______") + g!key (code.local "_______key") + g!val (code.local "_______val")] + [_ _ =val=] (<type>.applied (all <>.and + (<type>.exactly dictionary.Dictionary) + (<type>.exactly .Text) + encoded))] + (in (` (is (~ (@JSON#encoded inputT)) + (|>> ((~! dictionary.entries)) + ((~! list#each) (function ((~ g!_) [(~ g!key) (~ g!val)]) + [(~ g!key) ((~ =val=) (~ g!val))])) + ((~! dictionary.of_list) (~! text.hash)) + {/.#Object}))))) + (do ! + [[_ =sub=] (<type>.applied (all <>.and + (<type>.exactly .Maybe) encoded))] - (in (` (is (~ (@JSON#encoded inputT)) - (|>> ((~! dictionary.entries)) - ((~! list#each) (function ((~ g!_) [(~ g!key) (~ g!val)]) - [(~ g!key) ((~ =val=) (~ g!val))])) - ((~! dictionary.of_list) (~! text.hash)) - {/.#Object}))))) - (do ! - [[_ =sub=] (<type>.applied ($_ <>.and - (<type>.exactly .Maybe) - encoded))] - (in (` (is (~ (@JSON#encoded inputT)) - ((~! ..nullable) (~ =sub=)))))) - (do ! - [[_ =sub=] (<type>.applied ($_ <>.and - (<type>.exactly .List) - encoded))] - (in (` (is (~ (@JSON#encoded inputT)) - (|>> ((~! list#each) (~ =sub=)) ((~! sequence.of_list)) {/.#Array}))))) - (do ! - [.let [g!_ (code.local "_______") - g!input (code.local "_______input")] - members (<type>.variant (<>.many encoded)) - .let [last (-- (list.size members))]] - (in (` (is (~ (@JSON#encoded inputT)) - (function ((~ g!_) (~ g!input)) - (case (~ g!input) - (~+ (list#conjoint (list#each (function (_ [tag g!encoded]) - (if (n.= last tag) - (.list (` {(~ (code.nat (-- tag))) #1 (~ g!input)}) - (` ((~! /.json) [(~ (code.frac (..tag (-- tag)))) - #1 - ((~ g!encoded) (~ g!input))]))) - (.list (` {(~ (code.nat tag)) #0 (~ g!input)}) - (` ((~! /.json) [(~ (code.frac (..tag tag))) - #0 - ((~ g!encoded) (~ g!input))]))))) - (list.enumeration members)))))))))) - (do ! - [g!encoders (<type>.tuple (<>.many encoded)) - .let [g!_ (code.local "_______") - g!members (|> (list.size g!encoders) - list.indices - (list#each (|>> n#encoded code.local)))]] - (in (` (is (~ (@JSON#encoded inputT)) - (function ((~ g!_) [(~+ g!members)]) - ((~! /.json) [(~+ (list#each (function (_ [g!member g!encoded]) - (` ((~ g!encoded) (~ g!member)))) - (list.zipped_2 g!members g!encoders)))])))))) - ... Type recursion - (do ! - [[selfC non_recC] (<type>.recursive encoded) - .let [g! (code.local "____________")]] - (in (` (is (~ (@JSON#encoded inputT)) - ((~! ..rec_encoded) (.function ((~ g!) (~ selfC)) - (~ non_recC))))))) - <type>.recursive_self - ... Type applications - (do ! - [partsC (<type>.applied (<>.many encoded))] - (in (` ((~+ partsC))))) - ... Polymorphism - (do ! - [[funcC varsC bodyC] (<type>.polymorphic encoded)] - (in (` (is (All ((~ g!_) (~+ varsC)) - (-> (~+ (list#each (function (_ varC) (` (-> (~ varC) /.JSON))) - varsC)) - (-> ((~ (poly.code *env* inputT)) (~+ varsC)) - /.JSON))) - (function ((~ funcC) (~+ varsC)) - (~ bodyC)))))) - <type>.parameter - <type>.recursive_call - ... If all else fails... - (<>.failure (format "Cannot create JSON encoder for: " (type.format inputT))) - )))) + (in (` (is (~ (@JSON#encoded inputT)) + ((~! ..nullable) (~ =sub=)))))) + (do ! + [[_ =sub=] (<type>.applied (all <>.and + (<type>.exactly .List) + encoded))] + (in (` (is (~ (@JSON#encoded inputT)) + (|>> ((~! list#each) (~ =sub=)) ((~! sequence.of_list)) {/.#Array}))))) + (do ! + [.let [g!_ (code.local "_______") + g!input (code.local "_______input")] + members (<type>.variant (<>.many encoded)) + .let [last (-- (list.size members))]] + (in (` (is (~ (@JSON#encoded inputT)) + (function ((~ g!_) (~ g!input)) + (case (~ g!input) + (~+ (list#conjoint (list#each (function (_ [tag g!encoded]) + (if (n.= last tag) + (.list (` {(~ (code.nat (-- tag))) #1 (~ g!input)}) + (` ((~! /.json) [(~ (code.frac (..tag (-- tag)))) + #1 + ((~ g!encoded) (~ g!input))]))) + (.list (` {(~ (code.nat tag)) #0 (~ g!input)}) + (` ((~! /.json) [(~ (code.frac (..tag tag))) + #0 + ((~ g!encoded) (~ g!input))]))))) + (list.enumeration members)))))))))) + (do ! + [g!encoders (<type>.tuple (<>.many encoded)) + .let [g!_ (code.local "_______") + g!members (|> (list.size g!encoders) + list.indices + (list#each (|>> n#encoded code.local)))]] + (in (` (is (~ (@JSON#encoded inputT)) + (function ((~ g!_) [(~+ g!members)]) + ((~! /.json) [(~+ (list#each (function (_ [g!member g!encoded]) + (` ((~ g!encoded) (~ g!member)))) + (list.zipped_2 g!members g!encoders)))])))))) + ... Type recursion + (do ! + [[selfC non_recC] (<type>.recursive encoded) + .let [g! (code.local "____________")]] + (in (` (is (~ (@JSON#encoded inputT)) + ((~! ..rec_encoded) (.function ((~ g!) (~ selfC)) + (~ non_recC))))))) + <type>.recursive_self + ... Type applications + (do ! + [partsC (<type>.applied (<>.many encoded))] + (in (` ((~+ partsC))))) + ... Polymorphism + (do ! + [[funcC varsC bodyC] (<type>.polymorphic encoded)] + (in (` (is (All ((~ g!_) (~+ varsC)) + (-> (~+ (list#each (function (_ varC) (` (-> (~ varC) /.JSON))) + varsC)) + (-> ((~ (poly.code *env* inputT)) (~+ varsC)) + /.JSON))) + (function ((~ funcC) (~+ varsC)) + (~ bodyC)))))) + <type>.parameter + <type>.recursive_call + ... If all else fails... + (<>.failure (format "Cannot create JSON encoder for: " (type.format inputT))) + )))) (poly: decoded (with_expansions @@ -253,76 +253,76 @@ (function (_ type) (` (</>.Parser (~ (poly.code *env* type))))))] inputT <type>.next] - ($_ <>.either - <basic> - <time> - (do ! - [unitT (<type>.applied (<>.after (<type>.exactly unit.Qty) - <type>.any))] - (in (` (is (~ (@JSON#decoded inputT)) - ((~! <>.codec) (~! qty_codec) (~! </>.any)))))) - (do ! - [[_ _ valC] (<type>.applied ($_ <>.and - (<type>.exactly dictionary.Dictionary) - (<type>.exactly .Text) - decoded))] - (in (` (is (~ (@JSON#decoded inputT)) - ((~! </>.dictionary) (~ valC)))))) - (do ! - [[_ subC] (<type>.applied (<>.and (<type>.exactly .Maybe) - decoded))] - (in (` (is (~ (@JSON#decoded inputT)) - ((~! </>.nullable) (~ subC)))))) - (do ! - [[_ subC] (<type>.applied (<>.and (<type>.exactly .List) + (all <>.either + <basic> + <time> + (do ! + [unitT (<type>.applied (<>.after (<type>.exactly unit.Qty) + <type>.any))] + (in (` (is (~ (@JSON#decoded inputT)) + ((~! <>.codec) (~! qty_codec) (~! </>.any)))))) + (do ! + [[_ _ valC] (<type>.applied (all <>.and + (<type>.exactly dictionary.Dictionary) + (<type>.exactly .Text) decoded))] - (in (` (is (~ (@JSON#decoded inputT)) - ((~! </>.array) ((~! <>.some) (~ subC))))))) - (do ! - [members (<type>.variant (<>.many decoded)) - .let [last (-- (list.size members))]] - (in (` (is (~ (@JSON#decoded inputT)) - ($_ ((~! <>.or)) - (~+ (list#each (function (_ [tag memberC]) - (if (n.= last tag) - (` (|> (~ memberC) - ((~! <>.after) ((~! </>.this_boolean) (~ (code.bit #1)))) - ((~! <>.after) ((~! </>.this_number) (~ (code.frac (..tag (-- tag)))))) - ((~! </>.array)))) - (` (|> (~ memberC) - ((~! <>.after) ((~! </>.this_boolean) (~ (code.bit #0)))) - ((~! <>.after) ((~! </>.this_number) (~ (code.frac (..tag tag))))) - ((~! </>.array)))))) - (list.enumeration members)))))))) - (do ! - [g!decoders (<type>.tuple (<>.many decoded))] - (in (` (is (~ (@JSON#decoded inputT)) - ((~! </>.array) ($_ ((~! <>.and)) (~+ g!decoders))))))) - ... Type recursion - (do ! - [[selfC bodyC] (<type>.recursive decoded) - .let [g! (code.local "____________")]] - (in (` (is (~ (@JSON#decoded inputT)) - ((~! <>.rec) (.function ((~ g!) (~ selfC)) - (~ bodyC))))))) - <type>.recursive_self - ... Type applications - (do ! - [[funcC argsC] (<type>.applied (<>.and decoded (<>.many decoded)))] - (in (` ((~ funcC) (~+ argsC))))) - ... Polymorphism - (do ! - [[funcC varsC bodyC] (<type>.polymorphic decoded)] - (in (` (is (All ((~ g!_) (~+ varsC)) - (-> (~+ (list#each (|>> (~) </>.Parser (`)) varsC)) - (</>.Parser ((~ (poly.code *env* inputT)) (~+ varsC))))) - (function ((~ funcC) (~+ varsC)) - (~ bodyC)))))) - <type>.parameter - <type>.recursive_call - ... If all else fails... - (<>.failure (format "Cannot create JSON decoder for: " (type.format inputT))) - )))) + (in (` (is (~ (@JSON#decoded inputT)) + ((~! </>.dictionary) (~ valC)))))) + (do ! + [[_ subC] (<type>.applied (<>.and (<type>.exactly .Maybe) + decoded))] + (in (` (is (~ (@JSON#decoded inputT)) + ((~! </>.nullable) (~ subC)))))) + (do ! + [[_ subC] (<type>.applied (<>.and (<type>.exactly .List) + decoded))] + (in (` (is (~ (@JSON#decoded inputT)) + ((~! </>.array) ((~! <>.some) (~ subC))))))) + (do ! + [members (<type>.variant (<>.many decoded)) + .let [last (-- (list.size members))]] + (in (` (is (~ (@JSON#decoded inputT)) + (all ((~! <>.or)) + (~+ (list#each (function (_ [tag memberC]) + (if (n.= last tag) + (` (|> (~ memberC) + ((~! <>.after) ((~! </>.this_boolean) (~ (code.bit #1)))) + ((~! <>.after) ((~! </>.this_number) (~ (code.frac (..tag (-- tag)))))) + ((~! </>.array)))) + (` (|> (~ memberC) + ((~! <>.after) ((~! </>.this_boolean) (~ (code.bit #0)))) + ((~! <>.after) ((~! </>.this_number) (~ (code.frac (..tag tag))))) + ((~! </>.array)))))) + (list.enumeration members)))))))) + (do ! + [g!decoders (<type>.tuple (<>.many decoded))] + (in (` (is (~ (@JSON#decoded inputT)) + ((~! </>.array) (all ((~! <>.and)) (~+ g!decoders))))))) + ... Type recursion + (do ! + [[selfC bodyC] (<type>.recursive decoded) + .let [g! (code.local "____________")]] + (in (` (is (~ (@JSON#decoded inputT)) + ((~! <>.rec) (.function ((~ g!) (~ selfC)) + (~ bodyC))))))) + <type>.recursive_self + ... Type applications + (do ! + [[funcC argsC] (<type>.applied (<>.and decoded (<>.many decoded)))] + (in (` ((~ funcC) (~+ argsC))))) + ... Polymorphism + (do ! + [[funcC varsC bodyC] (<type>.polymorphic decoded)] + (in (` (is (All ((~ g!_) (~+ varsC)) + (-> (~+ (list#each (|>> (~) </>.Parser (`)) varsC)) + (</>.Parser ((~ (poly.code *env* inputT)) (~+ varsC))))) + (function ((~ funcC) (~+ varsC)) + (~ bodyC)))))) + <type>.parameter + <type>.recursive_call + ... If all else fails... + (<>.failure (format "Cannot create JSON decoder for: " (type.format inputT))) + )))) (syntax: .public (codec [inputT <code>.any]) (in (.list (` (is (codec.Codec /.JSON (~ inputT)) |