Git Product home page Git Product logo

border-types's Introduction

border-types

A tool to keep you types in syncs across your stack

Usage

TODO

Contributing

  • You need stack installed
  • You can run the test suite with stack test
  • Please add a spec file and write tests, you can look to the test suite in tests/ to look at an example

border-types's People

Watchers

 avatar  avatar  avatar

border-types's Issues

Which language to use?

The options that are (currently) being discussed are:

  • Haskell
  • Reason
  • Elm

I'm kind of excited at the possibility of using Haskell, but is has a pretty major drawback: we'd need to cross-compiling in order to publish to multiple platforms. This doesn't looks super challenging, and the steps are outlined here: (derived from elm-platform)

Reason would be super cool as well! Since it can be compiled to JS, it can be run using Node to avoid the cross-platform issue mentioned above. We will probably need to use Reason-JS interop to have access to the JS ecosystem, since I'm not sure how many thing will be written in native Reason (such as a YAML parser or something).

Not sure how using Elm would work, but I imagine we could somehow bootstrap it with Reason or something to take in cli arguments and apply them to an Elm program, similar to how elm-typescript-interop does with typescript.

Overall all of these languages are great, and I'm psyched on which ever we choose.

How to determine what types to generate?

This is a continuation of https://discourse.elm-lang.org/t/generating-border-types/722

Basically we are not sure if we want to generate types from format (YAML, JSON, etc) that defines them, or generate them from an Elm program that exposes ports.

My preference is using something like YAML or JSON, for a few reason:

  • Don't need to figure out how to use/reuse/rewrite the Elm parser to get information about the types
  • Can generate type for ports and a server
  • Types will always be in sync. If generated from ports, ports could change but the host language types might not be re-generated. If generated from a separate file, then the types will be generated for both Elm and the host language at the same time forcing them to be in sync

Overall "How will this work"

I need to do more learning about how to generate the types in Elm and the host languages, and what approaches exist. I'm assuming we'd use ASTs. To my understanding, it is basically a parser and programmatic representation of a programming language data.

Elm ASTs:

Typescript ASTs:

Reason ASTs:

  • (I didn't find anything)

Type Definition Schema

How should the type definition config file look?

From https://www.notion.so/A-script-to-generate-both-Reason-and-Elm-types-for-ports-5177b1c921c74d55a05be797ef4a43bf but in JSON

{
    "<type-name>": {
        "<constructor-name1>": {
            "<field-name1>": "<field-type>"
        },
        "<constructor-name2>": {
            "<field-name2>": "<field-type>"
        },
    }
}

Would translate to:

-- ELM
type <type-name>
     = <constructor-name1> {<field-name1> : <field-type>}
     | <constructor-name2> {<field-name2> : <field-type>}
// REASON
type <type-name> =
    | <constructor-name1>({. "<field-name1>": <field-type>})
    | <constructor-name2>({. "<field-name2>": <field-type>})

This is all fine and good, however there are a few things that this does not address:
a) Defining a top-level type alias (and the how to differentiate between unions & aliases)
b) Defining arguments on union types that are not records
c) Defining a top-level type OR type alias, and reference it later

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.