【发布时间】:2015-08-21 16:54:14
【问题描述】:
以下代码在 Haskell 中完全没问题:
dh :: Int -> Int -> (Int, Int)
dh d q = (2^d, q^d)
a = dh 2 (fst b)
b = dh 3 (fst a)
Agda 中的类似代码无法编译(终止检查失败):
infixl 9 _^_
_^_ : ℕ → ℕ → ℕ
x ^ zero = 1
x ^ suc n = x * (x ^ n)
dh : ℕ -> ℕ -> ℕ × ℕ
dh d q = 2 ^ d , q ^ d
mutual
a = dh 2 (proj₁ b)
b = dh 3 (proj₁ a)
a 的定义使用 a,它在结构上并不更小,因此是循环。似乎终止检查器不会查看 dh 的定义。
我尝试过使用 coduction,设置选项 --termination-depth=4 -- 没有帮助。
在mutual 块中插入{-# NO_TERMINATION_CHECK #-} 会有所帮助,但它看起来像是作弊。
有没有一种干净的方法可以让 Agda 编译代码? Agda 的终止检查器是否有一些基本限制?
【问题讨论】:
标签: recursion agda termination coinduction