Skip to content

Rework case definition for better sum type support #1

@kurtmilam

Description

@kurtmilam

It should be possible to allow automatic expansion of cases based on sum types.

The new case definition might look like this for something other than a sum type:

Shape =
  { Circle: { Type: $.RecordType( { origin: Point, radius: $.ValidNumber } )
            , area: ( { radius } ) => Math.PI * radius * radius
            , move
            , move2
            } 
  }

With a little work ( marking the constructors, Types, standard and user-defined functions so they can be identified), the following should be a workable syntax for defining a case based on another sum type:

Shape =
  { Triangle }

Assuming Triangle is a sum type with two cases, Base and Equilateral, that should allow for syntax like:
Shape.Triangle.Base( { definition } ) and Shape.Triangle.Equilateral.Type, as well as for tagging a triangle correctly by passing it into Shape().

Shape.tags( equilateralTriangleDef ) could return [ 'Triangle', 'Triangle.Base', 'Triangle.Equilateral' ].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions