Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom ADTs should come with accompanying JSON parsers. #359

Open
ilyasergey opened this issue Jan 6, 2019 · 0 comments
Open

Custom ADTs should come with accompanying JSON parsers. #359

ilyasergey opened this issue Jan 6, 2019 · 0 comments
Assignees
Labels
enhancement New feature or request in-progress This issue is being worked on

Comments

@ilyasergey
Copy link
Contributor

ilyasergey commented Jan 6, 2019

The rough idea, extracted from a recent discussion. Let us have fixpoint combinator.

let rec fix pf = pf (fun _ -> fix pf)

Then each (possibly recursive) type can be also compiled to a JSON parser of its values in a parser-combinator style. For example:

type Tree = Leaf | Node of Tree * Uint32 * Tree

would be compiled to something like:

let node_parser self = seq parse_string("Node") @@ seq (self ()) @@ seq parse_uint32 (self())
let leaf_parser = parse_string "Leaf"
let tree_parser = fix (fun self -> alt leaf_parser (node_parser self))

Parsers for polymorphic types would need to take lists of parsers for data types, corresponding to their type parameters, which they can use in their implementation.

let pair_parser params = 
  let a_parser = get params 1 in
  let b_parser = get params 2 in
  seq parse_string("Pair") @@ seq a_parser b_parser
@ilyasergey ilyasergey added enhancement New feature or request in-progress This issue is being worked on labels Jan 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request in-progress This issue is being worked on
Projects
None yet
Development

No branches or pull requests

2 participants