Git Product home page Git Product logo

Comments (2)

jaredramirez avatar jaredramirez commented on August 20, 2024

An alternate schema that would satisfy points a & b is:

[
    {
        "name": "<type-name>",
        "kind": "alias",
        "value": "<field-type>"
    },
    {
        "name": "<type-name>",
        "kind": "alias",
        "value": {
             "<field-name1>": "<field-type>"
             "<field-name2>": "<field-type>"
        }
    },
    {
        "name": "<type-name2>",
        "kind": "union",
        "constructors": {
             "<constructor-name1>": {
                 "<field-name1>": 
                     {
                         "name": "<type-name3>",
                         "kind": "alias",
                         "fields": {
                             "<sub-field-name1>": "<sub-field-type>"
                             "<sub-field-name2>": "<sub-field-type>"
                         }
                     },
             },
             "<constructor-name2>": {
                 "<field-name2>": "<field-type>"
            },
        }
    }
]

In this schema, <field-type> is any one of Int, Float, Bool, String or another alias or union declaration.

This does not address associations between types, but the fact that you can defined nested types can partially solve this.

@splodingsocks what are you thoughts on this schema?

from border-types.

jaredramirez avatar jaredramirez commented on August 20, 2024

I an now thinking something like this

{
    "languages": [
        {
            "name": "elm",
            "outputPath": "./src/elm/Data",
            "elmFormatPath": "./path/to/elmFormat" // optional
        },
        {
            "name": "reason",
            "outputPath": "./src/reason/Data",
            "refmt": 3, // syntax version
            "refmtPath": "./path/to/refmt" // optional
        }
    ],
    "types": [
        {
            "name": "<type-name1>",
            "kind": "alias",
            "value": <primitive-type1>
        },
        {
            "name": "<type-name2>",
            "kind": "union",
            "constructors": {
                 "<constructor-name1>": [
                     <primitive-type2>,
                     <primitive-type3>
                 ],
                 "<constructor-name2>": [
                     <primitive-type4>
                ],
            }
        }
    ]
}

This would spit out

// ELM
type alias <type-name1> = <primitive-type1>

typo <type-name1>
    = <constructor-name1> <primitive-type2> <primitive-type3>
    | <constructor-name2> <primitive-type4>
// REASON
type <type-name1> = <primitive-type1>

type <type-name2> =
    | <constructor-name1>(<primitive-type2>, <primitive-type3>)
    | <constructor-name2>(<primitive-type4>)

In this example, <primitive-typeN> can be string, int, float, bool, list (represented as a list with 1 element), unit (represented as an empty list), an x-tuple (represented as a list with many elements), or a record (an object).
A list would look like:

[<primative-type>]

A unit would look like:

[]

An x-tuple would look like:

[<primative-type>, <primative-type>, <primative-type>]

A record would look like:

{
    "<field1>" : <primative-type>,
    "<field2>" : <primative-type>
}

I don't like how similar lists & tuples are in this example, and am thinking of alternative ways to represent lists and tuple in json.

Adding a top level object also provides the ability to gather metadata about the type generation. In this example it's being used to specify the output paths but it can also be used to specify language version (elm 0.18 vs 0.19), and various other things as we think of them

from border-types.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.