You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 m
Since 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 #-}
)
The text was updated successfully, but these errors were encountered:
For reasons (TM) I wanted to implement a recursor for natural numbers in
agda2hs
. Since pattern matching onNatural
is not allowed in Haskell, I thought I'd useifDec
instead. However, in the non-zero branch I need to take the predecessor in order to make the recursive call:predNat
needs a somewhat complicated (but sensible) type:Since it doesn't seem possible to implement
predNat
with the primitives thatagda2hs
currently provides, I thought it could be nice to add it as a primitive, so more complex functions likerecNat
can be implemented on top. WDYT?(The definition of
_≟_
is currently missing from theagda2hs
prelude, but it can readily be defined:)
The text was updated successfully, but these errors were encountered: