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

Should consistentTypes compare kinds up to holes? #1146

Open
brprice opened this issue Sep 19, 2023 · 1 comment
Open

Should consistentTypes compare kinds up to holes? #1146

brprice opened this issue Sep 19, 2023 · 1 comment
Labels
core Core issue question This issue is a question, not a bug or feature request

Comments

@brprice
Copy link
Contributor

brprice commented Sep 19, 2023

For reference in the sequel, consider the following two snippets:

Firstly, how we typecheck an embedding of a synthesisable term in a checkable position

e ∈ t'   t ~ t'
---------------
    t ∋ e

(t', e') <- synth e
if consistentTypes t t'
then pure $ addChkMetaT t e'
else case sh of
NoSmartHoles -> throwError' (InconsistentTypes t t')
SmartHoles -> enholeT t e'

(ignore the fact that smartholes may transform e into e' for our current purposes)

The definition of t ~ t'

-- | Two types are consistent if they are equal (up to IDs and alpha) when we
-- also count holes as being equal to anything.
consistentTypes :: Type -> Type -> Bool
consistentTypes x y = uncurry eqType $ holepunch x y
where
-- We punch holes in each type so they "match" in the sense that
-- they have holes in the same places. (At least, until we find
-- obviously different constructors.)
holepunch (TEmptyHole _) _ = (TEmptyHole (), TEmptyHole ())
holepunch _ (TEmptyHole _) = (TEmptyHole (), TEmptyHole ())
holepunch (THole _ _) _ = (TEmptyHole (), TEmptyHole ())
holepunch _ (THole _ _) = (TEmptyHole (), TEmptyHole ())
holepunch (TFun _ s t) (TFun _ s' t') =
let (hs, hs') = holepunch s s'
(ht, ht') = holepunch t t'
in (TFun () hs ht, TFun () hs' ht')
holepunch (TApp _ s t) (TApp _ s' t') =
let (hs, hs') = holepunch s s'
(ht, ht') = holepunch t t'
in (TApp () hs ht, TApp () hs' ht')
holepunch (TForall _ n k s) (TForall _ m l t) =
let (hs, ht) = holepunch s t
in -- Perhaps we need to compare the kinds up to holes also?
(TForall () n k hs, TForall () m l ht)
holepunch s t = (s, t)


Now consider the definition

foo : ∀a:* . ?
foo = ? : ∀b:* . ?

which is creatable by

  • in type, insert a forall which automatically writes * for the kind
  • in term, create an annotation and then a forall

What should happen if we change the kind of b to a hole?
Currently this creates a term which is not type-correct, so smartholes kicks in and gives

foo : ∀a:* . ?
foo = {? ? : ∀b:? . ? ?}

but perhaps it would be more intuitive and more consistent to consider these two annotations consistent, giving

foo : ∀a:* . ?
foo = ? : ∀b:? . ?

Note that one level down we have that the following is type-correct (with no non-empty holes!)

bar : Int ->  ?
bar = ? : ? -> ?

Whilst I think that this would be straightforward to implement, and it seems like it would be a good idea, I have not thought about it enough to convince myself that there are no lurking pitfalls.

@brprice brprice added the triage This issue needs triage label Sep 19, 2023
@dhess dhess added core Core issue question This issue is a question, not a bug or feature request and removed triage This issue needs triage labels Sep 19, 2023
@dhess dhess removed their assignment Sep 19, 2023
@georgefst
Copy link
Contributor

I'd say it's not obvious where the mismatch stems from, so this sounds like something we should do (unless of course we get rid of KHole completely - discussed as unlikely recently in #1095 (comment), but I note that #108 is still open).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core issue question This issue is a question, not a bug or feature request
Projects
None yet
Development

No branches or pull requests

3 participants