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

PHI 9 - Type Variables and Type Aliases #10

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft

Conversation

bkase
Copy link

@bkase bkase commented Mar 21, 2021

Merges in content from PHI 5 (type variables) with latex judgments
for bidirectional type elaboration and kind synthesis/analysis. Will
follow up with content from the PHI 3 (type aliases) later.

bkase added 3 commits March 20, 2021 20:23
Merges in content from PHI 5 (type variables) with latex judgements
for bidirectional type elaboration and kind synthesis/analysis. Will
follow up with content from the PHI 3 (type aliases) later.
\begin{minipage}{\linewidth}
\judgbox
{\elabAna{\hPhi}{\htau}{\hkappa_1}{\dtau}{\hkappa_2}{\Delta}}
{$\htau$ analyzes against type $\hkappa_1$ and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should say "kind" not "type"

\newcommand{\kconsistent}[2]{#1 \sim #2}

\newcommand{\hPhi}{\Phi}
\newcommand{\EmptyhPhi}{\emptyset} % From hand-written notes, Canonical forms lemma; page 14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use \cdot for both

```
type TPat.t =
| EmptyHole(MetaVar.t)
| TyVar(VarErrStatus.t, TyId.t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need a VarErrStatus here, since we're introducing a binding not consuming it


So that we can still assign a type properly to the resulting `DExp.t` we add the following new syntax:

`TyBindings(TyVarCtx.t, DHExp.t)` for abstract syntax
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why this needs to be a tyvarctx -- I think we can just turn each type alias line into a corresponding type alias expression in dhexp

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we could avoid having to deal with patterns in DHExp if we did it this way and this will scale if/when type-patterns get more complicated.

I can't think of a way to, in a single DHExp, capture all the possibilities of holes in different places of the UHExp type alias without copying all the rules over (or is this what you're suggesting?)

\begin{minipage}{\linewidth}
\judgbox
{\kconsubkind{\Delta;\hPhi}{\hkappa_1}{\hkappa_2}}
{$\hkappa_1$ is a consistent subkind of $\hkappa_2$}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we need a transitivity rule here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistent subkinding (and subtyping) isn’t transitive. Counter example:
S(Int) <~ ?
? <~ S(Bool)

but this is not true:
S(Int) <~ S(Bool)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, whoops.

Do you need a rule for S(t1) <~ S(t2) where t1 <~ t2?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think not yet (until polymorphism) because currently:

  1. S(tau) is only well-formed if tau has kind Ty
  2. forall types tau_1 and tau_2, tau_1 <~ tau_2 iff tau_1 === tau_2 -- and this is covered by the KCRespectEquiv rule

\begin{minipage}{\linewidth}
\judgbox
{\kformation{\Delta;\hPhi}{\hkappa}}
{$\hkappa$ forms a kind} \;\\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need rules for other kind forms

\begin{minipage}{\linewidth}
\judgbox
{\kequiv{\Delta;\hPhi}{\hkappa_1}{\hkappa_2}}
{$\hkappa_1$ is equivalent to $\hkappa_2$} \;\\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need rules for other type forms

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused what is you mean by other type forms -- I'm not clear what's missing here

\begin{minipage}{\linewidth}
\judgbox
{\kcequiv{\Delta;\hPhi}{\dtau_1}{\dtau_2}{\hkappa}}
{$\dtau_1$ is equivalent to $\dtau_2$ and has kind $\hkappa_2$} \;\\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^ same as my reply, I'm not sure what's missing

@hejohns
Copy link

hejohns commented Jun 15, 2021

hejohns@8f53339
@cyrus- found typo while I was referencing this Phi during OH

@hejohns
Copy link

hejohns commented Jun 19, 2021

hejohns@4201af8
Is this a bug in KSVar?
related-- given
type V = Int in type T = V in ...
is T \equiv Int supposed to be derivable?

@cyrus-
Copy link
Member

cyrus- commented Jun 20, 2021

Looks right to me. Why do you think it may be a bug?

Yes, T \equiv Int should be derivable in that case.

@hejohns
Copy link

hejohns commented Jun 22, 2021

I must be missing something.
I'm unable to rigorously show T \equiv Int is NOT derivable, but there seems to me a problematic circularity where to show T \equiv Int with the current rules, you essentially have to show S(T) \equiv S(Int), which is only the conclusion of KESingEquiv, which has T \equiv Int as the premiss.
Similarly, trying to show T \equiv V and using transitivity seems to be impossible.
That said, type-aliases-2 handles this snippet just fine.
Will be at OH tomorrow.

@hejohns
Copy link

hejohns commented Jun 25, 2021

https://raw.githubusercontent.com/hejohns/hazel-etc/trunk/9-type-aliases/kind-judgements.ESDefine-simple.pdf
keeping let type line elaboration the same, adds a simple type equality judgment st t :: S(\tau) concludes t \equiv \tau

https://raw.githubusercontent.com/hejohns/hazel-etc/trunk/9-type-aliases/kind-judgements.ESDefine-weird-knd-ana.pdf
keeping let type line elaboration the same, adds a "weird" (@cyrus- ) kind ana judgment st t :: S(\tau) concludes t <= S(\tau)

https://raw.githubusercontent.com/hejohns/hazel-etc/trunk/9-type-aliases/kind-judgements.KSVar-natural.pdf
changes type var kind syn to be "natural", but requires let type line elaboration to be modified (see pdf), and some other ancillary details.

while the current let type line elaboration-- where the kind synthesized by the definition is added to the context-- seems natural at first, it may not be so. After all, you essentially want to singleton wrap/lift the type definition. Using the synthesized kind only serves this purpose if we define a somewhat unnatural KSVar rule, which definitely works, but rubs me the wrong way.
That said, forcing the more natural KSVar judgment results in a slightly quirky let type line elaboration rule(s)-- but to me, the quirkiness isn't as bad as the KSVar strangeness.

edit: had to be more careful with KSVar-natural. Should probably should go with ESDefine-simple after all.

@hejohns
Copy link

hejohns commented Jun 28, 2021

https://raw.githubusercontent.com/hejohns/hazel-etc/trunk/9-type-aliases/kind-judgements.subkind.pdf
one more option, similar to the rule in Stone, Harper 2006, where S(t) \consistentsubkind \kappa if t :: \kappa \in \Phi

as much as I want to modify KSVar, keeping it and adding this subkinding judgment is more decorous

@cyrus-
Copy link
Member

cyrus- commented Jun 29, 2021

I think adding a kind analysis rule for type variables is the right solution. I've attached an annotation with that rule, as well as some other notes to think about for both of you @bkase and @hejohns. We can discuss in OH.
Uploading kinding-notes-june29.pdf…

@bkase
Copy link
Author

bkase commented Jun 29, 2021

@cyrus- i think your upload failed, can you retry it?

@cyrus-
Copy link
Member

cyrus- commented Jun 29, 2021

kinding-notes-june29.pdf

@hejohns
Copy link

hejohns commented Jun 30, 2021

@hejohns
Copy link

hejohns commented Jul 4, 2021

https://raw.githubusercontent.com/hejohns/hazel-etc/trunk/9-type-aliases/mphi-9-type-aliases/mphi.pdf
This should be self readable for the interested/bored, but I don't think it's strictly necessary to before talking about it next week.
The main article is about the desire for labeled singletons in the metatheory. There are some additional notes on tangential matters.
A written out form for "why proving kind analysis soundness is ugly w/o labeled singletons in the metatheory" is at the end.
It is very short.
The outstanding issue with holes and labeled singletons-- as pointed out by @cyrus- --, and in the future type constructors, is perturbing.

@bkase
Copy link
Author

bkase commented Jul 7, 2021

hazelgrove/hazel@45e180c uses higher-singletons and the S_{S_k(c)}(c') === S_k(c) rule to resolve the variable issue

@hejohns hejohns force-pushed the 9-type-aliases-redux branch from f6fcfcc to 4410cd5 Compare July 17, 2021 01:40
@hejohns
Copy link

hejohns commented Jul 17, 2021

^force push was rollback from accidental push upstream (confused remotes/muscle memory)

@bkase , @cyrus- recommended making a new phi for the (wip) system w/ type constructors/Pi/Sigma-kinds, and updating this one to reflect the code as is.
https://raw.githubusercontent.com/hejohns/hazel-etc/trunk/9-type-aliases/kind-judgements.diff.pdf
is a latexdiff generated pdf diff of the updates. Should be as expected. Singleton labels are only for typvar propogation.
The bnf got cut off but it's just S(\htau) => S_{\hkappa}(\htau).

https://raw.githubusercontent.com/hejohns/hazel-etc/trunk/9-type-aliases/diff.patch (the full/binary patch; includes pdf)

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.

3 participants