Skip to content

Algebraic data types and pattern matching #12

@quasarbright

Description

@quasarbright

We're already planning on adding objects and arrays, but we also want union types. Tuples would be cool too. You get union types for free in a dynamically typed language because it's like everything is a union over all types. But if we add static typing, it'll be nice to have discriminated unions. Or if we want to be really cool, we could do non-discriminated unions like type script. But that'd be hard. Structural subtyping would be cool too, but that's a topic for another issue

At any rate, We should make pattern matching constructs like const {x,y} = pointObj in js and tuple unpacking (x,y) = pair if we do tuples. It could all be syntactic sugar. But we should allow for nested stuff like const {x,y as {z, p as (a,b)}} = {x:1,y:{z:2,p:(3,4)}}

We've been meaning to make a desugaring pass anyway, since we're doing inline desugaring in the interpreter for stuff like let x = 2; -> let x; x = 2;. Having a dedicated pass and two AST types would make future passes much easier to implement

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestspecial syntaxA feature with syntax that deviates from javascript

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions