Skip to content

Render type parameters as lambdas, and render typedefs more like term defs #1034

@dhess

Description

@dhess

After some debate, we've decided that we would like to treat type parameters as being akin to term-level lambdas. Though they're not completely analogous, for our purposes, they're close enough, and the general consensus is that treating type parameters in this way will hopefully provide a bridge which leverages what students have learned about function parameters/lambdas to help them understand type parameters, in the sense that a type parameter binds a (variable) name to the scope in which the type's value constructors are defined.

To make the proposal more concrete, here's an example of how we might render a parameterized type in Primer's text representation, after adopting this proposal:

type Maybe : Type → Type

Maybe = Λα . Nothing | Just α

[Note here type is used as data is used in Haskell, and not as a type alias as would be the case in Haskell. Also, we're thinking that, as part of this change, we will drop the * notation in the frontend and switch to Type, as then it's obvious that parameterized types take an argument of type Type.]

Also, we should then change how we render typedefs in tree representation to match how we render term defs — currently, with the type of the type on the left, and the constructors on the right. We also tentatively agreed that it would be good to render value constructors under the type lambdas, as expressions would be in function bodies, and from left to right with boxes around each constructor that mimic how we render value constructors in match with patterns in terms, in order to reinforce the association of pattern-matching to the value constructors of the corresponding type.

Note that we don't expect this to require any major backend changes, as this is more or less a rendering decision, and not a change to the language's semantics. However, it should be reflected in Primer's terminology and documentation.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions