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

Add preliminary support for inductive families #133

Merged
merged 1 commit into from
Feb 21, 2019
Merged

Conversation

ollef
Copy link
Owner

@ollef ollef commented Feb 21, 2019

This is roughly based on Abel & Cockx's paper
(http://www2.tcs.ifi.lmu.de/~abel/lhs-checking-submitted.pdf).

It's enough to implement as data types some simple things like
propositional equality, finite sets, and vectors, but there's some stuff
that still doesn't work very well or is missing, notably:

  • Coverage and redundancy checks are incomplete.
  • Error messages are bad.
  • Dot patterns are missing.

Data type indices are desugared in the following way:

type Equals a b where
  Refl : Equals a a

becomes

type Equals a b where
  Refl : Builtin.Equals a b => Equals a b

We can see that a Builtin.Equals (which is distinct from Equals, the
type being defined in the example) constraint has been inserted for the
second parameter of the Refl constructor because its type differs from
the type definition's head. This makes Equals an ordinary
parameterised data type again, leaving the job of constraining indices
to Builtin.Equals.

Builtin.Equals is a constraint that's special-cased in the compiler.
If it occurs in a pattern, it's automatically matched using the SplitEq
rule from the aforementioned paper. If the constraint occurs unsolved in
an expression, its two arguments are unified and the constraint is
solved with Builtin.Refl (its lone constructor) as the solution.

This is roughly based on Abel & Cockx's paper
(http://www2.tcs.ifi.lmu.de/~abel/lhs-checking-submitted.pdf).

It's enough to implement as data types some simple things like
propositional equality, finite sets, and vectors, but there's some stuff
that still doesn't work very well or is missing, notably:

* Coverage and redundancy checks are incomplete.
* Error messages are bad.
* Dot patterns are missing.

Data type indices are desugared in the following way:

```
type Equals a b where
  Refl : Equals a a
```

becomes

```
type Equals a b where
  Refl : Builtin.Equals a b => Equals a b
```

We can see that a `Builtin.Equals` (which is distinct from `Equals`, the
type being defined in the example) constraint has been inserted for the
second parameter of the `Refl` constructor because its type differs from
the type definition's head. This makes `Equals` an ordinary
parameterised data type again, leaving the job of constraining indices
to `Builtin.Equals`.

`Builtin.Equals` is a constraint that's special-cased in the compiler.
If it occurs in a pattern, it's automatically matched using the SplitEq
rule from the aforementioned paper. If the constraint occurs unsolved in
an expression, its two arguments are unified and the constraint is
solved with `Builtin.Refl` (its lone constructor) as the solution.
@ollef ollef merged commit e3a2839 into master Feb 21, 2019
@ollef ollef deleted the inductive-families branch February 21, 2019 21:28
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.

1 participant