Skip to content

Commit 06c6605

Browse files
committed
Tactic: new inline macro
1 parent 69c3195 commit 06c6605

25 files changed

+490
-168
lines changed

Class/Convertible.agda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# OPTIONS --safe --without-K #-}
12
module Class.Convertible where
23

34
open import Class.Convertible.Core public

Class/Convertible/Core.agda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# OPTIONS --safe --without-K #-}
12
module Class.Convertible.Core where
23

34
open import Meta.Prelude

Class/Convertible/Foreign.agda

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{-# OPTIONS --without-K #-}
2+
module Class.Convertible.Foreign where
3+
4+
open import Meta.Prelude
5+
6+
open import Class.Functor
7+
open import Class.Bifunctor
8+
9+
open import Class.Convertible.Core
10+
open import Class.HasHsType.Core
11+
12+
open import Foreign.Haskell using (Pair; Either)
13+
open import Foreign.Haskell.Coerce using (coerce)
14+
15+
instance
16+
Convertible-Pair : Convertible₂ _×_ Pair
17+
Convertible-Pair = λ where
18+
.to coerce ∘ bimap to to
19+
.from bimap from from ∘ coerce
20+
21+
Convertible-Either : Convertible₂ _⊎_ Either
22+
Convertible-Either = λ where
23+
.to coerce ∘ bimap to to
24+
.from bimap from from ∘ coerce

Class/Convertible/Instances.agda

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# OPTIONS --safe --without-K #-}
12
module Class.Convertible.Instances where
23

34
open import Meta.Prelude
@@ -6,15 +7,11 @@ open import Class.Functor
67
open import Class.Bifunctor
78

89
open import Class.Convertible.Core
9-
1010
open import Class.HasHsType.Core
1111

1212
HsConvertible : (A : Set) ⦃ HasHsType A ⦄ Set
1313
HsConvertible A = Convertible A (HsType A)
1414

15-
open import Foreign.Haskell using (Pair; Either)
16-
open import Foreign.Haskell.Coerce using (coerce)
17-
1815
instance
1916
Convertible-ℕ : Convertible ℕ ℕ
2017
Convertible-ℕ = λ where
@@ -27,19 +24,9 @@ instance
2724
Convertible-× : Convertible₂ _×_ _×_
2825
Convertible-× = Bifunctor⇒Convertible
2926

30-
Convertible-Pair : Convertible₂ _×_ Pair
31-
Convertible-Pair = λ where
32-
.to coerce ∘ bimap to to
33-
.from bimap from from ∘ coerce
34-
3527
Convertible-⊎ : Convertible₂ _⊎_ _⊎_
3628
Convertible-⊎ = Bifunctor⇒Convertible
3729

38-
Convertible-Either : Convertible₂ _⊎_ Either
39-
Convertible-Either = λ where
40-
.to coerce ∘ bimap to to
41-
.from bimap from from ∘ coerce
42-
4330
Convertible-List : Convertible₁ List List
4431
Convertible-List = λ where
4532
.to fmap to

Class/HasHsType.agda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# OPTIONS --safe --without-K #-}
12
module Class.HasHsType where
23

34
open import Class.HasHsType.Core public

Class/HasHsType/Core.agda

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# OPTIONS --safe --without-K #-}
12
module Class.HasHsType.Core where
23

34
open import Meta.Prelude

Class/HasHsType/Foreign.agda

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{-# OPTIONS --without-K #-}
2+
module Class.HasHsType.Foreign where
3+
4+
open import Meta.Prelude
5+
6+
open import Class.HasHsType.Core
7+
8+
open import Foreign.Haskell.Pair using (Pair)
9+
open import Foreign.Haskell.Either using (Either)
10+
11+
module _ ⦃ _ : HasHsType A ⦄ ⦃ _ : HasHsType B ⦄ where instance
12+
13+
iHsTy-Sum : HasHsType (A ⊎ B)
14+
iHsTy-Sum .HasHsType.HsType = Either (HsType A) (HsType B)
15+
16+
iHsTy-Pair : HasHsType (A × B)
17+
iHsTy-Pair .HasHsType.HsType = Pair (HsType A) (HsType B)

Class/HasHsType/Instances.agda

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
{-# OPTIONS --safe --without-K #-}
12
module Class.HasHsType.Instances where
23

34
open import Meta.Prelude
45

5-
open import Foreign.Haskell.Pair using (Pair)
6-
open import Foreign.Haskell.Either using (Either)
7-
86
open import Class.HasHsType.Core
97

108
instance
@@ -21,12 +19,5 @@ module _ ⦃ _ : HasHsType A ⦄ where instance
2119
iHsTy-Maybe : HasHsType (Maybe A)
2220
iHsTy-Maybe .HasHsType.HsType = Maybe (HsType A)
2321

24-
module _ ⦃ _ : HasHsType B ⦄ where instance
25-
iHsTy-Fun : HasHsType (A B)
26-
iHsTy-Fun .HasHsType.HsType = HsType A HsType B
27-
28-
iHsTy-Sum : HasHsType (A ⊎ B)
29-
iHsTy-Sum .HasHsType.HsType = Either (HsType A) (HsType B)
30-
31-
iHsTy-Pair : HasHsType (A × B)
32-
iHsTy-Pair .HasHsType.HsType = Pair (HsType A) (HsType B)
22+
iHsTy-Fun : ⦃ HasHsType B ⦄ HasHsType (A B)
23+
iHsTy-Fun {B = B} .HasHsType.HsType = HsType A HsType B

Meta/Prelude.agda

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ module Meta.Prelude where
55
-- ** stdlib re-exports
66
open import Level public
77
renaming (_⊔_ to _⊔ˡ_; suc to sucˡ; zero to zeroˡ)
8-
open import Function public
8+
variable
9+
ℓ ℓ′ ℓ″ : Level
10+
A B C D : Set
911

1012
open import Data.Bool public
1113
hiding (_≟_; _≤_; _≤?_; _<_; _<?_)
@@ -25,22 +27,26 @@ open import Data.Nat public
2527
open import Data.String public
2628
using (String; _<+>_)
2729

30+
open import Function public
31+
open import Relation.Nullary public
32+
using (Dec; yes; no)
2833
open import Relation.Binary.PropositionalEquality public
2934
hiding (preorder; setoid; [_]; module ≡-Reasoning; decSetoid)
3035

3136
-- ** helper funs
32-
lookupᵇ : {A B : Set} (A A Bool) List (A × B) A Maybe B
37+
lookupᵇ : (A A Bool) List (A × B) A Maybe B
3338
lookupᵇ f [] n = nothing
3439
lookupᵇ f ((k , v) ∷ l) n = if f k n then just v else lookupᵇ f l n
3540

36-
zipWithIndex : {A B : Set} (ℕ A B) List A List B
41+
zipWithIndex : (ℕ A B) List A List B
3742
zipWithIndex f l = zipWith f (upTo $ length l) l
3843
where open import Data.Fin; open import Data.List
3944

40-
enumerate : {A : Set} List A List (ℕ × A)
45+
enumerate : List A List (ℕ × A)
4146
enumerate = zipWithIndex _,_
4247

43-
-- ** variables
44-
variable
45-
ℓ ℓ′ ℓ″ : Level
46-
A B C D : Set
48+
_⁉_ : List A Maybe A
49+
_⁉_ = λ where
50+
[] _ nothing
51+
(x ∷ _) zero just x
52+
(_ ∷ xs) (suc n) xs ⁉ n

Reflection/Utils/Args.agda

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,13 @@ hide = λ where
6464
apply⋯ : Args Type Name Type
6565
apply⋯ is n = def n $ remove-iArgs $
6666
map (λ{ (n , arg i _) arg i (♯ (length is ∸ suc (toℕ n)))}) (zip (allFin $ length is) is)
67+
68+
-- Applying a list of arguments to a term of any shape.
69+
apply∗ : Term Args Term Term
70+
apply∗ f xs = case f of λ where
71+
(def n as) def n (as ++ xs)
72+
(con c as) con c (as ++ xs)
73+
(var x as) var x (as ++ xs)
74+
(pat-lam cs as) pat-lam cs (as ++ xs)
75+
(meta x as) meta x (as ++ xs)
76+
f f

0 commit comments

Comments
 (0)