Giter Site home page Giter Site logo

Implement Named Constructor syntax about ante HOT 2 OPEN

jfecher avatar jfecher commented on June 29, 2024
Implement Named Constructor syntax

from ante.

Comments (2)

jfecher avatar jfecher commented on June 29, 2024

If a contributor wants to work on this issue, feel free to tackle it in chunks. E.g. adding parser support first. Then in a later PR add name resolution support. During name resolution, we can desugar to a normal constructor expression with positional fields so that no later pass will need to handle these expressions.

MyStruct with field1 = expr1, ..., fieldN = exprN

Can be desugared to

_v1 = expr1
_v2 = expr2
MyStruct _v1 _v2

Where an outer block expression holds variable definitions for each field to preserve order of operations in case the fields need to be rearranged for the constructor expression. The fresh names generated for each variable should also be names that cannot clash with user's variable names. An easy way to achieve this is by prefixing the name with a symbol like $.

from ante.

jfecher avatar jfecher commented on June 29, 2024

The remaining work on this issue is to implement name resolution, type checking, and monomorphization for named constructors. It's likely that after name resolution we'll be able to desugar named constructors into regular constructors, e.g:

MyConstructor with
    field3 = expr3
    field2 = expr2
    field1 = expr1

Will desugar to:

// Fields are brought out into Definitions to preserve evaluation order.
// They're given a name guaranteed not to clash with any identifier in the source program.
$field3 = expr3
$field2 = expr2
$field1 = expr1
MyConstructor $field1 $field2 $field3

from ante.

Related Issues (20)

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.