Skip to content

Commit

Permalink
Upstream ByEq tactic
Browse files Browse the repository at this point in the history
  • Loading branch information
WhatisRT committed May 31, 2024
1 parent 02f80fd commit e834cf7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions Tactic.agda
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open import Tactic.Try public
open import Tactic.Rewrite public
open import Tactic.Extra public
open import Tactic.Existentials public
open import Tactic.ByEq public

open import Tactic.AnyOf public
open import Tactic.Assumption public
Expand Down
58 changes: 58 additions & 0 deletions Tactic/ByEq.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{-# OPTIONS --safe --without-K #-}
module Tactic.ByEq where

open import Meta hiding (TC)
open import MetaPrelude
open import Class.Functor.Core; open import Class.Functor.Instances
open import Class.Monad.Core; open import Class.Monad.Instances
open import Reflection using (TC; withNormalisation; inferType; unify)
open import Reflection.Utils

-- Introduce as many arguments as possible and then:
-- 1. for those of type `_ ≡ _`, unify with `refl`
-- 2. ignore the rest of the arguments (unify with `_`)
-- 3. unify the hole with `refl`
by-eq : Hole TC ⊤
by-eq hole = do
ty withNormalisation true $ inferType hole
let ps : Args Pattern
ps = argTys ty <&> fmap λ {(def (quote _≡_) _) quote refl ◇; _ dot unknown}
unify hole $ pat-lam [ clause [] ps (quote refl ◆) ] []

macro $by-eq = by-eq

private
-- test that macro works
_ : {n m k : ℕ} n ≡ m m ≡ k n ≡ k
_ = $by-eq

_ : {n m k x y : ℕ} n ≡ m x ≡ y m ≡ n
_ = $by-eq

-- test that tactic arguments work
f : {@(tactic by-eq) _ : {n m : ℕ} n ≡ m m ≡ n} Bool Bool
f = id

_ : f {λ where refl refl} true ≡ true
_ = refl

_ : f {$by-eq} true ≡ true
_ = refl

_ : f true ≡ true
_ = refl

-- test that normalisation works
Sym = {n m : ℕ} n ≡ m m ≡ n

g : {@(tactic by-eq) _ : Sym} Bool Bool
g = id

_ : g {λ where refl refl} true ≡ true
_ = refl

_ : g {$by-eq} true ≡ true
_ = refl

_ : g true ≡ true
_ = refl

0 comments on commit e834cf7

Please sign in to comment.