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

General inductive parameters #2506

Merged
merged 69 commits into from
Nov 15, 2023
Merged

General inductive parameters #2506

merged 69 commits into from
Nov 15, 2023

Conversation

janmasrovira
Copy link
Collaborator

@janmasrovira janmasrovira commented Nov 8, 2023

This pr allows inductive type parameters to be any type. Until now, they had to be exactly Type. This allows us to define more general traits such as the Monad and Functor, as shown in the new test.
This is only supported under the temporary --new-typechecker flag.

Pending work:

Update the positivity checker if necessary (@jonaprieto).
Update the necessary compilation steps in Core (@lukaszcz).
Add compilation tests.

@janmasrovira janmasrovira changed the title Inductive parameters General inductive parameters Nov 10, 2023
@janmasrovira janmasrovira changed the base branch from 2362-interleave-arity-and-type-checking to main November 10, 2023 00:21
janmasrovira added a commit that referenced this pull request Nov 12, 2023
- Closes #2362 

This pr implements a new typechecking algorithm. This algorithm can be
activated using the global flag `--new-typechecker`. This flag will only
take effect on the compilation pipeline but not the repl.

The main difference between the new and old algorithm is that the new
one inserts holes during typechecking. Thus, it does not require the
arity checker pass.

The new algorithm does not yet implement default arguments. The plan is
to make the change in the following steps:
1. Merge this pr.
2. Merge #2506.
3. Implement default arguments for the new algorithm.
4. Remove the arity checker and the old algorithm.

---------

Co-authored-by: Łukasz Czajka <[email protected]>
@janmasrovira janmasrovira added enhancement New feature or request typechecking labels Nov 13, 2023
@janmasrovira janmasrovira added this to the 0.5.4 milestone Nov 13, 2023
@janmasrovira janmasrovira marked this pull request as ready for review November 13, 2023 16:41
@jonaprieto jonaprieto requested review from lukaszcz and jonaprieto and removed request for lukaszcz November 14, 2023 09:10
@jonaprieto
Copy link
Collaborator

jonaprieto commented Nov 15, 2023

Shortly, we can merge this PR since it does not replace the default typechecker. However, we need to address the positivity checker separately. I added two examples below to make it clear that there is an issue, although it is not straightforward to me at the moment how to solve it.

module NegativeEvil;

type Evil (f : Type -> Type) :=
  | magic : f (Evil f) -> Evil f;

First, the Evil data type is not strictly positive but it passes our checker, so we have an issue. Second, ignoring the positivity condition over the Evil definition for a moment, consider the rest of this program.

type Empty := mkEmpty {}; 

toEmpty (A : Type) : Type := A -> Empty;

panic : toEmpty (Evil toEmpty) 
  | x@(magic h) := h x ;

god : Empty := panic (magic panic); 

The above produces the following error,

The expression panic has type:
  Evil λ! {A := A → Empty} → Empty
but is expected to have type:
  _ (Evil _)

The message is a bit difficult to understand, at least to me, so we must fix it too.
Also, this should typecheck ignoring the positivity condition.

Similarly as with Evil, one could derive a term of Empty using for example, other types like:

type Free (f : Type -> Type) (A : Type)
 : Type :=
| Leaf : A -> Free f A
| Branch : f (Free f A) -> Free f A;

We can include these examples in a future PR fixing the pos. checker.

@rokopt could get benefit of being able to typecheck this Free data type, isn't it?
your BT A could be expressed as Free (\ {T := Prod T T}) A, or similar I'd say.

@rokopt
Copy link
Member

rokopt commented Nov 15, 2023

@rokopt could get benefit of being able to typecheck this Free data type, isn't it? your BT A could be expressed as Free (\ {T := Prod T T}) A, or similar I'd say.

Yes, that's right!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request typechecking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants