Klister custom type systems #232
Labels
discussion
documentation
Improvements or additions to documentation
enhancement
New feature or request
I think we should think about and document more explicitly what kind of type system extensions can be implemented in Klister.
For example, once we implement syntax parameters, I think we can claim that Klister supports custom typing rules involving multiple contexts. Each context is a syntax parameter. Every existing rule is automatically extended to pass it on unchanged, for example
becomes
The rules which care about that extra context are implemented as macros which look at this syntax pattern and set this parameter locally around the sub-terms. For example,
Can be implemented by a
let-box
macro which expands toNote that this technically implements the rule
But since
tmp1
andtmp2
are invisible toe2
, they can be ignored.This is a good start, especially since the context can have any shape, it is not restricted to be a map from symbol to type. If we allow overriding #%identifier, a #lang would even be able to hide Gamma from the user and to use Delta exclusively, which would make it possible to implement e.g. the linear lambda calculus.
Next, type formers. Above, the
Box
modality is implemented via a newtype wrapper around the runtime representation, Syntax. The data constructor is not exposed outside of the implementation of the #lang and its type system, so this implementation detail is invisible to the user. Box even shows up in error messages and participates in unification. This is good, but there are a few limitations:To address those limitations, we could allow indices other than Type as long as they provide a typeclass instance providing an implementation for unification and generalization. This also implies that typeclasses should be built-in after all.
Next, some judgments produce a context instead of consuming it, e.g. pattern-matching. I think this would be better served by a custom problem than a custom type. Still, it should be possible to use a custom type which is indexed by a type and a context.
Type systems are very varied, so I'm sure there are some type systems which cannot be implemented by the features above. But it seems sufficient for most purposes, I think?
The text was updated successfully, but these errors were encountered: