Skip to content
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

feat: report better types in API for embeddings #1068

Merged
merged 1 commit into from
Jun 10, 2023
Merged

Conversation

brprice
Copy link
Contributor

@brprice brprice commented Jun 10, 2023

For embeddings, (i.e. where we have both a checked-at and synthesised type), we must (with the current API design) choose one type to report as the type of the selection. Previously we chose the synthed, but we now:

  • if exactly one is a hole, then choose the other
  • otherwise, chose the synthed (As future work, we may want to change the api to report both types, or maybe "merge" the two types. However, it is not clear what the correct design is here. (Note that "merging" is somewhat awkward due to binders and needing to worry about alpha equivalence).)

Note that these two types must be consistent. Consider the situation where we are checking T ∋ e and discover that e ∈ S. If we did not have T ~ S, then this would be a type error, which smartholes would rectify by putting e in a non-empty hole, giving T ∋ {? e ?} ∈ ? and ? ∋ e ∈ S. In this case, we report that {? e ?} has type T and e has type S.

The most obvious place that this change will affect is asking for the type of an expression hole: these synthesise the hole type, but may be in a checkable context. We now report the type the context requires them to have, rather than a hole. However, there are other situations, such as (assuming swap ∈ ∀a b . Pair a b -> Pair b a) swap @Int @? (swap @Char @? ?) where the inner swap is checked at Pair Int ? and synthesises Pair ? Char.

For embeddings, (i.e. where we have both a checked-at and synthesised
type), we must (with the current API design) choose one type to report
as the type of the selection. Previously we chose the synthed, but we
now:
- if exactly one is a hole, then choose the other
- otherwise, chose the synthed
(As future work, we may want to change the api to report both types,
or maybe "merge" the two types. However, it is not clear what the
correct design is here. (Note that "merging" is somewhat awkward due
to binders and needing to worry about alpha equivalence).)

Note that these two types must be consistent. Consider the situation
where we are checking `T ∋ e` and discover that `e ∈ S`. If we did not
have `T ~ S`, then this would be a type error, which smartholes would
rectify by putting `e` in a non-empty hole, giving `T ∋ {? e ?} ∈ ?`
and `? ∋ e ∈ S`. In this case, we report that `{? e ?}` has type `T`
and `e` has type `S`.

The most obvious place that this change will affect is asking for the
type of an expression hole: these synthesise the hole type, but may be
in a checkable context. We now report the type the context requires
them to have, rather than a hole. However, there are other situations,
such as (assuming `swap ∈ ∀a b . Pair a b -> Pair b a`)
`swap @int @? (swap @char @? ?)` where the inner `swap` is checked at
`Pair Int ?` and synthesises `Pair ? Char`.

Signed-off-by: Ben Price <ben@hackworthltd.com>
@brprice brprice enabled auto-merge June 10, 2023 12:28
@brprice brprice added this pull request to the merge queue Jun 10, 2023
@brprice brprice merged commit 6fd3dd0 into main Jun 10, 2023
102 checks passed
@brprice brprice deleted the brprice/api-type-emb branch June 10, 2023 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants