-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add records to the Inferno language #103
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@goodlyrottenapple if you ever have a few moments this week, I'd love to get your thoughts on the changes to the type inference. I've mentioned you on some comments with some particular questions. Thanks!
where | ||
st = (emptySubst, cs) | ||
|
||
unifyMany :: [TypeError SourcePos] -> [InfernoType] -> [InfernoType] -> Solve Subst | ||
unifyMany :: [TypeError SourcePos] -> [InfernoType] -> [InfernoType] -> SolveState Int Subst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once everything works, I can clean this up and use some FreshVarState
or something instead of Int
@@ -1435,23 +1519,30 @@ prettyPrec isBracketed prec expr = | |||
<> elsePretty | |||
Op e1 _ _ (n, NoFix) ns (Ident op) e2 -> | |||
bracketWhen e2 (prec > n) $ | |||
prettyOpAux (n + 1) e1 <> (if hasTrailingComment e1 then hardline else mempty) | |||
prettyOpAux (n + 1) e1 | |||
<> (if hasTrailingComment e1 then hardline else mempty) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of these are also formatting changes...
@@ -42,6 +44,7 @@ data Value custom m | |||
| VEnum VCObjectHash Ident | |||
| VArray [Value custom m] | |||
| VTuple [Value custom m] | |||
| VRecord (Map.Map Ident (Value custom m)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. It reminds me of the evaluation environment!
@Daniel-Diaz I found some bugs in the PR, so I'm pushing a few new commits with some extra tests and the respective bug fixes. Hope you don't mind reviewing the new commits in the same PR so I can merge it in in a good state. :) The changes are:
I also updated the PR description with details of the new record syntax and types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR follows up on #103 by adding pattern matching for records. E.g. ```ocaml let f = fun r -> match r with { | {x = x; y = y} -> x + y } in f {x = 3.3; y = 5.1} ``` It also adds a type error when record literals or patterns use duplicate field names.
This PR brings records to the Inferno language.
Syntax:
Types:
A general record type looks like
{f1: t1; ...; fN: tN; 𝜌}
where 𝜌 is a type variable called a row variable representing either:⏊
: a special symbol denoting no further fields in the record, orf1': t1'; ...; fN': tN'
The example above has the following types:
Here, the concrete record
r1
has type{ht: double; wt: double}
(which is syntactic sugar for{ht: double; wt: double; ⏊}
, the record having exactly two fields), and the type of the functionbmi
uses a row variable'a
denotes the fact that it accepts as argument any record that has at least the fieldsht
andwt
.Differences to OCaml's Immediate Objects
The description above is very similar to OCaml's ad-hoc objects, except that we retain the row variables in the types and show it to the user. The example above in OCaml would have the types:
I decided to keep the row variables explicit for now, because it makes the quantification on the "rest of the record fields" more explicit when we manually annotate functions. We can always change the pretty-printer and parser later to be like OCaml and hide row variables using the
...
syntax, if we prefer.