-
Notifications
You must be signed in to change notification settings - Fork 18
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 a "syntax AST" for typedefs #175
Comments
Note: this syntax is mu-free; those should be implicit. |
Looks nice, especially with the translation from recursive definitions to explicit Some bikeshedding:
|
@fredrikNordvallForsberg Your comments make sense, I'll try updating the example so we can see how it looks like. I currently have no intuition about how to compile recursive types defintions into TMus, for example
This should compile to
Is it correct to replace every recursive definition by |
I've implemented your syntax @fredrikNordvallForsberg at 891c074 I couldn't use I was considering replacing
instead of
|
As a first approximation yes, but there is a subtlety with nested mus: every time you go under another mu, you need to shift the index of the variable being substituted in by one. |
That looks better, in my opinion. However I think it would still make sense to keep |
@fredrikNordvallForsberg Do you have an example of a recursive definition that compiles to two nested Regarding Unless we want to enforce |
A common example is finitarily branching trees (with data at the leaves, say):
which (if we keep the list anonymous) should compile to
unless I have messed up. The Leaf
Yes, that's what I had in mind, sorry if I was unclear! |
So I tried to retrofit your example into the proposed syntax but since sums involving constructors are automatically converted into a TMu with no scoping rules there is no way to inline the definition of list. It's the same as you've written:
This makes your proposal of having |
TDefs are now indexed by the number of free varibales as well as whether they have references or not. `TDef' 3 True` means there are three free variables and contains unbounded references. `TDef 0 False` means there are no free variables and all references are resolved. This allows us to recover totality when computing the Idris Type of a TDef using the `Ty` function. Also should allow us to remove the effectful compiling of a TDef in the haskell backend by first resolving all references into a debrujin index and extending the previous context with the new indices used by references. This comes at the cost of the existing dependent parser which is now basically broken until we find a way to fix it: - Either only parse TDefR which makes references unusable - Remove the dependent parse and write an index-free parser #175
TDefs are now indexed by the number of free varibales as well as whether they have references or not. `TDef' 3 True` means there are three free variables and contains unbounded references. `TDef 0 False` means there are no free variables and all references are resolved. This allows us to recover totality when computing the Idris Type of a TDef using the `Ty` function. Also should allow us to remove the effectful compiling of a TDef in the haskell backend by first resolving all references into a debrujin index and extending the previous context with the new indices used by references. This comes at the cost of the existing dependent parser which is now basically broken until we find a way to fix it: - Either only parse TDefR which makes references unusable - Remove the dependent parse and write an index-free parser #175
TDefs are now indexed by the number of free varibales as well as whether they have references or not. `TDef' 3 True` means there are three free variables and contains unbounded references. `TDef 0 False` means there are no free variables and all references are resolved. This allows us to recover totality when computing the Idris Type of a TDef using the `Ty` function. Also should allow us to remove the effectful compiling of a TDef in the haskell backend by first resolving all references into a debrujin index and extending the previous context with the new indices used by references. This comes at the cost of the existing dependent parser which is now basically broken until we find a way to fix it: - Either only parse TDefR which makes references unusable - Remove the dependent parse and write an index-free parser #175
TDefs are now indexed by the number of free varibales as well as whether they have references or not. `TDef' 3 True` means there are three free variables and contains unbounded references. `TDef 0 False` means there are no free variables and all references are resolved. This allows us to recover totality when computing the Idris Type of a TDef using the `Ty` function. Also should allow us to remove the effectful compiling of a TDef in the haskell backend by first resolving all references into a debrujin index and extending the previous context with the new indices used by references. This comes at the cost of the existing dependent parser which is now basically broken until we find a way to fix it: - Either only parse TDefR which makes references unusable - Remove the dependent parse and write an index-free parser #175
All #133 #164 #163 #172 require changes to the AST but do not necessarily change the semantics of the language. This means it would be possible to write a new syntax for typedefs that compiles down to
TDef n
and that is more ergonomic and feature rich than our core ASTTDef n
.Here is a small proposal for a new surface level syntax
this would compile down to
This would allow us to add new features to typedefs without having to change backends and making sure the semantics of the language are never changed.
I've added a branch which implement this syntax as an EDSL (without the conversion to TDef) here: https://github.com/typedefs/typedefs/tree/surface-syntax the relevant file is
src/DSL.idr
This feature would also fix #23
Could you please tell me what you think @clayrat @fredrikNordvallForsberg @wires @epost ?
The text was updated successfully, but these errors were encountered: