Open evincarofautumn opened 7 years ago
It looks like we can represent an expression .label
with a Get
constructor for Term
, then infer the type as α → α::label, that is, whatever the type of label
is in α. Zonking does the actual lookup and error reporting, and then the Get
term can be desugared to a match
after inference. α can be any “concrete type”, which I guess is just a type constructor or constructor application.
For updating fields, I’m considering a notation like .(value -> name)
, or .(-> name)
to take the value from the stack, but this doesn’t quite work for initialisation.
Large structures are unwieldy to use without named fields. I propose we reuse the
as
notation for specifying field names.I think it’s good to impose the restriction that fields are either all named, or all anonymous. Next, we need a syntax and semantics for field access, and the conventional
.name
notation is as good as anything.Initially, field accesses will not be polymorphic—
x.y
means “look up the index of the fieldy
in the inferred type ofx
and generate the appropriatematch
expression”. If the field isn’t present, or the inferred type is polymorphic, the compiler will produce an error.This restriction can be relaxed later, for example if we add extensible records.
If the same field name is present in multiple constructors of a type, then the field must have the same type in each.
If the field is present in some cases but not others, a field access produces an
Optional
.We may also need syntax for initialising and replacing fields by name, like Haskell’s record notation.
But so far I haven’t been able to come up with anything satisfactory for Kitten.