-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Labels
enhancementNew feature or requestNew feature or request
Description
For reasons (TM) I wanted to implement a recursor for natural numbers in agda2hs. Since pattern matching on Natural is not allowed in Haskell, I thought I'd use ifDec instead. However, in the non-zero branch I need to take the predecessor in order to make the recursive call:
recNat : (a : @0 Nat → Set)
→ (z : a 0)
→ (s : (m : Nat) → a m → a (suc m))
→ (n : Nat) → a n
recNat a z s n = ifDec (n ≟ 0)
(λ where {{refl}} → z)
(λ {{n≠0}} →
case predNat n n≠0 of λ where
(m ⟨ refl ⟩) → s m (recNat a z s m))
{-# COMPILE AGDA2HS recNat #-}predNat needs a somewhat complicated (but sensible) type:
predNat : (n : Nat) → @0 (n ≡ 0 → ⊥) → ∃ Nat λ m → n ≡ suc mSince it doesn't seem possible to implement predNat with the primitives that agda2hs currently provides, I thought it could be nice to add it as a primitive, so more complex functions like recNat can be implemented on top. WDYT?
(The definition of _≟_ is currently missing from the agda2hs prelude, but it can readily be defined:
_≟_ : {{_ : Eq a}} {{_ : IsLawfulEq a}} → (x y : a) → Dec (x ≡ y)
x ≟ y = (x == y) ⟨ isEquality x y ⟩
{-# COMPILE AGDA2HS _≟_ inline #-})
wasabi315
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request