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

Add is_ind, is_constructor, is_proj #195

Merged
merged 3 commits into from Jun 16, 2016

Conversation

JasonGross
Copy link
Member

No description provided.

@jonleivent
Copy link

Are those the only kind_of_term left that Ltac can't distinguish via syntax or existing predicates?

I wonder if it would be better to have a Coq inductive that mirrors kind_of_term (maybe just with argless constructors?), and just have a "kind of" tactic (in the spirit of "type of") that returns one of those constructors. One could then write "match kind of x with" in Ltac. Of course, one does "match x with" now and picks out distinguishing syntactic structure - but some kinds don't have any.

@JasonGross
Copy link
Member Author

We have

  | Rel       of int
  | Var       of Id.t
  | Meta      of metavariable
  | Evar      of 'constr pexistential
  | Sort      of sorts
  | Cast      of 'constr * cast_kind * 'types
  | Prod      of Name.t * 'types * 'types
  | Lambda    of Name.t * 'types * 'constr
  | LetIn     of Name.t * 'constr * 'types * 'constr
  | App       of 'constr * 'constr array
  | Const     of constant puniverses
  | Ind       of inductive puniverses
  | Construct of constructor puniverses
  | Case      of case_info * 'constr * 'constr * 'constr array
  | Fix       of ('constr, 'types) pfixpoint
  | CoFix     of ('constr, 'types) pcofixpoint
  | Proj      of projection * 'constr

We have is_fix, is_cofix, is_evar, is_var. I believe Rel and Meta are not supposed to be visible at any point (someone correct me if I'm wrong). Cast is very fragile (most reduction tactics remove them), it handles things like (x : T) : U, x <: T, x <+ T for casts, vm_casts, native_casts. Sort is:

Ltac is_sort x :=
  lazymatch x with
  | Type => idtac
  | Set => idtac
  | Prop => idtac
  | _ => fail 0 "not a sort"
  end.

You can get Prod by matching against forall x, _; Lambda by matching against (fun x => _); LetIn by matching against let x := _ in _; App by matching against ?f ?x, Case by matching against match _ with _ => _ end. This PR gives Ind, Construct, Proj.

You might be able to get Const as:

Tactic Notation "is_const" ref(x) := idtac.

in 8.6, but I'm not sure.

This leaves the following

  • Rel, Meta - probably inaccessible
  • Cast - probably irrelevant to most tactic code
  • Const - probably fine as a default case, possibly doable in Ltac

@jonleivent
Copy link

Yes - it seems like:
Tactic Notation "is_const" reference(x) := idtac.
works in 8.5. It's a bit ugly, but may be a useful idiom for other predicates as well (is_integer, is_uconst, etc.).

@JasonGross
Copy link
Member Author

It will not work for is_uconst; there are implicit casts that are automatically inserted there.

@maximedenes
Copy link
Member

So would it make sense to provide is_constant, to avoid fragile implementations of it?

@JasonGross
Copy link
Member Author

Probably. I've added a commit to provide is_const, and another to update CHANGES. (Someone should document is_evar, has_evars, is_proj, etc..., but that can be done after the merge window closes)

@letouzey letouzey merged commit eab9b01 into coq:trunk Jun 16, 2016
@JasonGross JasonGross deleted the is-ind-construct-proj branch July 21, 2016 17:21
@Zimmi48 Zimmi48 modified the milestone: 8.6beta1 Jul 21, 2017
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

Successfully merging this pull request may close these issues.

None yet

5 participants