Module Shared_ast.Encoding

JSON encoding functions for Catala values

Runtime values to JSON encodings correspondence

- Unit: {} (empty JSON object)

- Bool: true | false (JSON boolean)

- Money: 123 (JSON integer) | 123.45 (JSON number) | "123" (JSON string)
  Note:
    - integer and string representations map to monetary units and not cents
    - floats are truncated to the second decimal

- Integer: 123 (JSON integer) | "123" (JSON string)

- Decimal: 123 (JSON integer) | 123.45 (JSON number) | "1/3" (JSON string)
  Note: we rely on [Q.of_string] for decoding strings

- Date: "1970-01-31" (JSON string)
  Note: we rely on [Dates_calc.date_of_string]

- Duration: "1 years", "2 months" or "12 days" (JSON string)

- Enum:
  - Unit constructors: "A" (JSON string)
  - Non-unit constructors: {"B": <json value>} (JSON object)

- Struct: { "x": <json value>, "y": <json value>, ...} (JSON object)

- Array: [ <json value>, <json value>, ...] (JSON array)

- Tuple: [ <json value>, <json value>, ...] (JSON array)
val make_encoding : Shared_ast__.Definitions.decl_ctx -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> Catala_runtime.runtime_value Json_encoding.encoding

Computes a JSON encoding of a Catala type using runtime_value as an intermediate representation.

val scope_input_encoding : Shared_ast__.Definitions.ScopeName.t -> Shared_ast__.Definitions.decl_ctx -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> Catala_runtime.runtime_value Json_encoding.encoding

Same as make_encoding but adds a title and a description to the generated JSON-schema expliciting that this represent a scope input structure.

val scope_output_encoding : Shared_ast__.Definitions.ScopeName.t -> Shared_ast__.Definitions.decl_ctx -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> Catala_runtime.runtime_value Json_encoding.encoding

Same as make_encoding but adds a title and a description to the generated JSON-schema expliciting that this represent a scope output structure.

val parse_json : Catala_runtime.runtime_value Json_encoding.encoding -> Yojson.Safe.t -> Catala_runtime.runtime_value

Parse a JSON using the given encoding as validation schema.

val convert_to_dcalc : Shared_ast__.Definitions.decl_ctx -> 'm Shared_ast__.Definitions.mark -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> Catala_runtime.runtime_value -> ((< monomorphic : Shared_ast__.Definitions.yes ; polymorphic : Shared_ast__.Definitions.yes ; overloaded : Shared_ast__.Definitions.no ; resolved : Shared_ast__.Definitions.yes ; syntacticNames : Shared_ast__.Definitions.no ; scopeVarStates : Shared_ast__.Definitions.no ; scopeVarSimpl : Shared_ast__.Definitions.no ; explicitScopes : Shared_ast__.Definitions.no ; defaultTerms : Shared_ast__.Definitions.yes ; custom : Shared_ast__.Definitions.no >, < monomorphic : Shared_ast__.Definitions.yes ; polymorphic : Shared_ast__.Definitions.yes ; overloaded : Shared_ast__.Definitions.no ; resolved : Shared_ast__.Definitions.yes ; syntacticNames : Shared_ast__.Definitions.no ; scopeVarStates : Shared_ast__.Definitions.no ; scopeVarSimpl : Shared_ast__.Definitions.no ; explicitScopes : Shared_ast__.Definitions.no ; defaultTerms : Shared_ast__.Definitions.yes ; custom : Shared_ast__.Definitions.no >, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Shared_ast__.Definitions.boxed

Conversion function from a runtime_value to a default calculus expression.

val convert_to_lcalc : Shared_ast__.Definitions.decl_ctx -> 'm Shared_ast__.Definitions.mark -> Shared_ast__.Definitions.naked_typ Catala_utils.Mark.pos -> Catala_runtime.runtime_value -> ((< monomorphic : Shared_ast__.Definitions.yes ; polymorphic : Shared_ast__.Definitions.yes ; overloaded : Shared_ast__.Definitions.no ; resolved : Shared_ast__.Definitions.yes ; syntacticNames : Shared_ast__.Definitions.no ; scopeVarStates : Shared_ast__.Definitions.no ; scopeVarSimpl : Shared_ast__.Definitions.no ; explicitScopes : Shared_ast__.Definitions.no ; defaultTerms : Shared_ast__.Definitions.no ; custom : Shared_ast__.Definitions.no >, < monomorphic : Shared_ast__.Definitions.yes ; polymorphic : Shared_ast__.Definitions.yes ; overloaded : Shared_ast__.Definitions.no ; resolved : Shared_ast__.Definitions.yes ; syntacticNames : Shared_ast__.Definitions.no ; scopeVarStates : Shared_ast__.Definitions.no ; scopeVarSimpl : Shared_ast__.Definitions.no ; explicitScopes : Shared_ast__.Definitions.no ; defaultTerms : Shared_ast__.Definitions.no ; custom : Shared_ast__.Definitions.no >, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed Shared_ast__.Definitions.boxed

Conversion function from a runtime_value to a lambda calculus expression.

val convert_from_gexpr : Shared_ast__.Definitions.decl_ctx -> ((_, _, 'm) Shared_ast__.Definitions.base_gexpr, 'm Shared_ast__.Definitions.mark) Catala_utils.Mark.ed -> Catala_runtime.runtime_value

Conversion function from a generic expression to a runtime value. This functions expects the expression to be composed of encodable-only nodes (e.g., no lambdas, closures, etc.)