diff options
Diffstat (limited to 'stdlib/source/polytypic')
-rw-r--r-- | stdlib/source/polytypic/lux/data/format/json.lux | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/stdlib/source/polytypic/lux/data/format/json.lux b/stdlib/source/polytypic/lux/data/format/json.lux index 391556a50..23b959bc5 100644 --- a/stdlib/source/polytypic/lux/data/format/json.lux +++ b/stdlib/source/polytypic/lux/data/format/json.lux @@ -53,29 +53,29 @@ (def: low_mask Nat (|> 1 (i64.left_shifted 32) --)) (def: high_mask Nat (|> low_mask (i64.left_shifted 32))) -(implementation: nat_codec +(def: nat_codec (codec.Codec JSON Nat) - - (def: (encoded input) - (let [high (|> input (i64.and high_mask) (i64.right_shifted 32)) - low (i64.and low_mask input)] - {/.#Array (sequence (|> high .int int.frac {/.#Number}) - (|> low .int int.frac {/.#Number}))})) - (def: decoded - (</>.result (</>.array - (do <>.monad - [high </>.number - low </>.number] - (in (n.+ (|> high frac.int .nat (i64.left_shifted 32)) - (|> low frac.int .nat)))))))) + (implementation + (def: (encoded input) + (let [high (|> input (i64.and high_mask) (i64.right_shifted 32)) + low (i64.and low_mask input)] + {/.#Array (sequence (|> high .int int.frac {/.#Number}) + (|> low .int int.frac {/.#Number}))})) + (def: decoded + (</>.result (</>.array + (do <>.monad + [high </>.number + low </>.number] + (in (n.+ (|> high frac.int .nat (i64.left_shifted 32)) + (|> low frac.int .nat))))))))) -(implementation: int_codec +(def: int_codec (codec.Codec JSON Int) - - (def: encoded - (|>> .nat (at nat_codec encoded))) - (def: decoded - (|>> (at nat_codec decoded) (at try.functor each (|>> .int))))) + (implementation + (def: encoded + (|>> .nat (at nat_codec encoded))) + (def: decoded + (|>> (at nat_codec decoded) (at try.functor each (|>> .int)))))) ... Builds a JSON generator for potentially inexistent values. (def: (nullable writer) @@ -85,16 +85,16 @@ {.#None} {/.#Null} {.#Some value} (writer value)))) -(implementation: qty_codec +(def: qty_codec (All (_ unit) (codec.Codec JSON (unit.Qty unit))) - - (def: encoded - (|>> ((debug.private unit.out')) - (at ..int_codec encoded))) - (def: decoded - (|>> (at ..int_codec decoded) - (at try.functor each (debug.private unit.in'))))) + (implementation + (def: encoded + (|>> ((debug.private unit.out')) + (at ..int_codec encoded))) + (def: decoded + (|>> (at ..int_codec decoded) + (at try.functor each (debug.private unit.in')))))) (poly: encoded (with_expansions |