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

[Feature] Please add tmTry #874

Open
JasonGross opened this issue Mar 26, 2023 · 0 comments
Open

[Feature] Please add tmTry #874

JasonGross opened this issue Mar 26, 2023 · 0 comments

Comments

@JasonGross
Copy link
Contributor

JasonGross commented Mar 26, 2023

I'd like to see something like

tmTry : forall {A:Type@{t}}, TemplateMonad A -> TemplateMonad (option_try A)

with

Monomorphic Variant exn : Set := GenericError.

Variant option_try (A : Type) : Type := my_Value (val : A) | my_Error (err : exn).

Arguments my_Value {A} val.
Arguments my_Error {A} _.

(and perhaps someday extend exn to hold more kinds of errors?), so that the following work without error:

From MetaCoq.Template Require Import All.

Import MCMonadNotation.
Import bytestring.
Open Scope bs.
Open Scope list_scope.

MetaCoq Run (tmDefinition "a" I;; tmTry (tmDefinition "a" I) >>= tmPrint).
MetaCoq Run (tmTry (tmDefinition "b" I);; mp <- tmCurrentModPath tt;; tmUnquote (tConst (mp, "b") []) >>= tmPrint).
MetaCoq Run (tmDefinition "c" I;; mp <- tmCurrentModPath tt;;
             v <- tmTry (tmUnquoteTyped False (tConst (mp, "c") []));;
             match v with
             | my_Value v => ret (inl v)
             | my_Error _ => v' <- tmUnquoteTyped True (tConst (mp, "c") []);;
                             ret (inr v')
             end >>= tmPrint).
MetaCoq Run (tmAxiom "a'" True;; tmTry (tmAxiom "a'" True) >>= tmPrint).
MetaCoq Run (tmTry (tmAxiom "b'" True);; mp <- tmCurrentModPath tt;; tmUnquote (tConst (mp, "b'") []) >>= tmPrint).
MetaCoq Run (tmAxiom "c'" True;; mp <- tmCurrentModPath tt;;
             v <- tmTry (tmUnquoteTyped False (tConst (mp, "c'") []));;
             match v with
             | my_Value v => ret (inl v)
             | my_Error _ => v' <- tmUnquoteTyped True (tConst (mp, "c'") []);;
                             ret (inr v')
             end >>= tmPrint).
Universes u0 u1.
Constraint u0 < u1.
MetaCoq Run (u <- tmQuote Type@{u0};;
             v <- tmTry (tmUnquoteTyped Type@{u0} u);;
             match v with
             | my_Value v => ret (v -> True)
             | my_Error _ => v' <- tmUnquoteTyped Type@{u1} v;;
                             ret (v' -> True)
             end >>= tmPrint).

(See also this Zulip thread)

JasonGross added a commit to JasonGross/metacoq that referenced this issue Mar 28, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Mar 28, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Mar 31, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Apr 1, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Apr 2, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Apr 2, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Apr 2, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Apr 2, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Apr 2, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Apr 2, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Apr 2, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Apr 2, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Apr 2, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Apr 3, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Apr 3, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
JasonGross added a commit to JasonGross/metacoq that referenced this issue Apr 3, 2023
Partial work towards MetaCoq#874.  Does not support `tmDefinition`, `tmAxiom`,
etc.
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

No branches or pull requests

1 participant