Skip to content

Types with mutual recursion are not supported #155

@jmfallecker

Description

@jmfallecker

Discriminated unions that are self-referential and any mutually recursive types are not supported. Using the $id and $ref keys in JSON should allow this type of structure to be serialized.

for a type definition like such:

type A = { B of B } and B = { A of A }

the json should end up being something like:

{
"A": {
"$id": "1",
"B": { "$ref": "2" }
},
"B": {
"$id": "2",
"A": { "$ref": "1" }
}
}

This is an incredibly simplified example, but there's an approach we can take using reflection to figure out what properties cause a cycle in a generic data structure. Once we've identified the cycle, we can use comparison of all other fields (excluding the cyclical part) to understand which records reference which other records.

I've included a first draft of a function to determine if a type is recursive or not.

isRecursive.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions