ice1000
ice1000

Reputation: 6569

How to define an alias in Agda's type delaration?

My code:

law : ∀ a x → ((suc a) * (suc a) ÷ (suc a) ⟨ x ⟩) →ℕ ≡ (suc a , refl)
law a x = refl

I think there's too many suc a and I want to give an alias to suc a, something like (this code just describes my idea, it doesn't compile):

law : ∀ a x → ((s : suc a) * s ÷ s ⟨ x ⟩) →ℕ ≡ (s , refl)
law a x = refl

Can I achieve that?

Upvotes: 4

Views: 490

Answers (1)

effectfully
effectfully

Reputation: 12715

Sure. You can use let

law : ∀ a x → let s = suc a in (s * s ÷ s ⟨ x ⟩) →ℕ ≡ (s , refl)
law a x = refl

or define an anonymous module:

module _ (a : ℕ) where
  s = suc a
  law : ∀ x → (s * s ÷ s ⟨ x ⟩) →ℕ ≡ (s , refl)
  law x = refl

Outside of the module law has the same type signature as the one you provided.

Upvotes: 6

Related Questions