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

Define smart constructors for data types as notations #153

Closed
MarvinLira opened this issue Jul 27, 2020 · 1 comment · Fixed by #180
Closed

Define smart constructors for data types as notations #153

MarvinLira opened this issue Jul 27, 2020 · 1 comment · Fixed by #180
Assignees
Labels
Coq Related to Coq back end or base library enhancement New feature or request

Comments

@MarvinLira
Copy link
Contributor

Description

Currently for each constructor of each data type a smart constructor is defined that lifts the return value of that constructor into a monadic value.

Definition MyPair_ (Shape : Type) (Pos : Shape -> Type) {a b : Type} (x : Free Shape Pos a) (y : Free Shape Pos b)
   : Free Shape Pos (MyPair Shape Pos a b) :=
  pure (myPair_ x y).

It would be nice if those smart constructors would be implemented as Notation instead of Definition.

Motivation

The approach with the Definition has two disadvantages:

  • The smart constructor is not automatically used by Coq for output.
    Destructing a Free Shape Pos (MyPair Shape Pos a b) twice yields a pure (myPair_ fx fy) instead of a MyPair_ fx fy.
  • Some simple tactics of coq fail because they do not unfold smart constructors.
    Lemma lem1 : forall (p : MyPair Shape Pos a b),
      f (pure p) = C.
    Proof. Admitted.
    
    Lemma lem2 : forall (fx : Free Shape Pos a) (fy : Free Shape Pos b),
      f (MyPair_ Shape Pos fx fy) = C.
    Proof.
      intros fx fy.
      Fail rewrite lem1.
    Admitted.
    
    Lemma lem3 : forall (fx : Free Shape Pos a) (fy : Free Shape Pos b),
      f (pure (myPair_ fx fy)) = C.
    Proof.
      intros fx fy.
      Fail rewrite lem2.
    Admitted.

Both points do not apply if a Notation is used.

@MarvinLira MarvinLira added enhancement New feature or request Coq Related to Coq back end or base library labels Jul 27, 2020
@MarvinLira MarvinLira self-assigned this Jul 27, 2020
MarvinLira added a commit that referenced this issue Aug 22, 2020
Smart constructors are now generated as `Notation` instead of `Definition`.
MarvinLira added a commit that referenced this issue Aug 22, 2020
The smart constructors toke `Shape` and `Pos` as arguments, this behavior has been restored.
MarvinLira added a commit that referenced this issue Aug 24, 2020
Fix bugs like unfolding smart constructors in proofs.
@MarvinLira
Copy link
Contributor Author

MarvinLira commented Aug 28, 2020

Issue #178 evaluates whether notation scopes should be used to qualify smart constructor notations.

MarvinLira added a commit that referenced this issue Aug 29, 2020
- Qualified smart constructor notations are no longer returned in a separate list but filtered out of the main list of sentences at some point.
- The local module for qualified smart constructors is no longer exported and has to be imported separately if desired.
MarvinLira added a commit that referenced this issue Aug 29, 2020
MarvinLira added a commit that referenced this issue Sep 3, 2020
Change `Import` to `Export` when importing the submodule for qualified notations of another module.
MajaRet pushed a commit that referenced this issue Sep 4, 2020
In order to test the generation of modules for qualified notations,
a test suite for the conversion of modules has been added.
MarvinLira added a commit that referenced this issue Sep 7, 2020
MajaRet pushed a commit that referenced this issue Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Coq Related to Coq back end or base library enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant