0

I have the following definition:

ren-refl′ : ∀ {Γ i t} (ts′ : List Ty) → (e : Tm {i} (Γ <>< ts′) t) → ren (keep* ts′ reflᵣ) e ≡ e
ren-refl′ {Γ} ts′ (var v)  rewrite keep*-refl {Γ} ts′ | ren-var-refl v = refl
ren-refl′ {Γ} ts′ (con e)  rewrite keep*-refl {Γ} ts′ | ren-con-refl e = refl

I would like to factor out the rewriting by keep*-refl {Γ} ts′ since we can do that (and do that uniformly) before pattern matching on the e argument.

The closest I got is with a pattern matching lambda:

ren-refl′ {Γ} ts′ rewrite keep*-refl {Γ} ts′ = λ
  { (var v) → cong var (ren-var-refl v)
  ; (con e) → cong con (ren-con-refl e)
  }

However, I don't like it because it requires me to do some cong shuffling that I wouldn't need with a straight rewrite; and I can't do a rewrite in a lambda.

Cactus
  • 27,075
  • 9
  • 69
  • 149
  • I presume that it wouldn't do to factor-out by creating a separate function that gets called after the first `rewrite`? The factored-out function would then perform the `ren-*-refl` rewrites. This adds some tedium that I suspect you don't want. – m0davis Jan 10 '18 at 03:41
  • Yeah factoring out the second step into a separate function is exactly what I want to avoid. – Cactus Jan 10 '18 at 03:57

2 Answers2

2

You might try Tactic.Reflection.Reright (sic) which I created in the agda-prelude. I imagine that you could replace the cong *s with reright. Caveat: I have not maintained that for some months and no longer use it.

Cactus
  • 27,075
  • 9
  • 69
  • 149
m0davis
  • 308
  • 1
  • 8
1

Quite often case_of_ and case_return_of_ from Function work fine inside lambdas, e. g:

open import Function

... λ {(var v) → case ren-var-refl v of λ {refl → refl}}
András Kovács
  • 29,931
  • 3
  • 53
  • 99
  • I like the idea behind it (and would hope to be able to abstract it further away with a `syntax` declaration), but it doesn't work for my particular use case: `I'm not sure if there should be a case for the constructor refl, because I get stuck when trying to solve the following unification problems (inferred index ≟ expected index): ren-con reflᵣ e ≟ e` – Cactus Jan 07 '18 at 04:09