-
Notifications
You must be signed in to change notification settings - Fork 34
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
RFC: user defined toplevel commands #374
Comments
I think having a builtin |
Yes, eventually we need to address this sort of thing. Another one to address is introduction of new binders, so we can write things like |
A more radical solution that may work in the short-term is to allow evaluation of strings, i.e., full reification of source code. |
We would need string manipulation functions in AML to use that. |
Yeah, the next step less horrible than that would expose the abstract syntax. But which one, |
I'm not sure what the point of that would be. |
You could create source code in the form of abstract syntax trees and then have it evaluated. Paired with a bit of support from the parser, this ought to allow flexible syntax extensions. |
What might that look like? |
I was thinking of MetaOcaml for instance, although that by itself doesn't let us define new syntax. There is also Growing a proof assistant which uses Racket to get new extensions in. I am not sure which way to go here, I'd prefer something that isn't super-complicated, even at the expense of expressivity. As you said at the beginning, the annoying thing would be to write all the constructors and inductions by hand all the time, we need to automate that sort of thing. It doesn't much matter whether the user writes
end or
|
Introduction
Some things can only be done by a sequence of toplevel commands. For instance, declaring an inductive with
n
constructors involves 1 constant for the inductive, n constants for the constructors, 1 constant for the induction principle and n constants for the computation rules of the induction principle.Andromeda wants to be generic enough to avoid having a specific
inductive
toplevel command, but we should give the user something that can be used to define an inductive in one command. This proposal would make the following AML code define HoTT'spaths
inductive, with an offscreeninductive
AML function (ie fully user defined) (I'm not imagining syntax for parameters for this example so they're done as indices instead).The
toplevel
toplevel command and ML typeThere are 2 new predefined types. The first is the type of lazy lists:
The second is a type which reifies (most) toplevel commands. For this example we will pretend that it only has the
constant
command.There is a new toplevel command called
toplevel
, used astoplevel c
wherec
is a computation of typellist toplevel
. It evaluatesc
to a value in the usual way (with the current top handler etc), then:lnil
it is done.lcons order thunk
it executes the toplevel command associated with theorder
, then continues astoplevel thunk ()
in the updated environment.For instance, the following declares constants
T : Type
thenx : T
:Maybe some commands should not go in the
toplevel
ML type. For instance I don't know if declaring ML types throughtoplevel
calls is a good idea.Desugaring with user toplevel
The desugar and typing phases now need to get information from the runtime phase to continue after a toplevel command. I haven't thought about this beyond noting it needs to be done yet.
New generics
As you can see in the above example we need
_constant "T"
to access the constant we just declared. This is cheating since_constant
does not exist (as a constructor, it exists as a pattern).Dynamic variables
When declaring an inductive type we want to add the computation rules to the beta hints.
This is the
now betas = c
toplevel command, which would be reified asNow of dynamic a and a
. Problems:dynamic a
, the updatersnow [in]
and an accessorcurrent x
(or some such thing).toplevel
command we would need a way to refer to the newly declared dynamic like with constants. However unlike with constants we can't ML type something like_dynamic "x"
.I'm not sure what the use of declaring new dynamics through
toplevel
would be. It's certainly not necessary for defining inductive TT types, as opposed to updating dynamics.Now of dynamic a and a
is not a correct constructor declaration as it's a GADT. How should we deal with this?Lexical binding and toplevel
The following prints
1
then"2"
since closures get the lexical part of the environment (whichx
belongs to) when constructed, so there's no shadowing or typing issue.Alternate syntax
Instead of using
toplevel c
to evaluatec
and do some commands, we could define new toplevel commands.It would be like
toplevel command args = c
, then after this we can evaluatecommand args
at the toplevel.The text was updated successfully, but these errors were encountered: