“Strictly positive” in Agda

自作多情 提交于 2019-11-30 03:18:31

HOAS doesn't work in Agda, because of this:

apply : Value -> Value -> Value
apply (FunVal f) x = f x
apply _ x = Error "Applying non-function"

w : Value
w = FunVal (\x -> apply x x)

Now, notice that evaluating apply w w gives you apply w w back again. The term apply w w has no normal form, which is a no-no in agda. Using this idea and the type:

data P : Set where
    MkP : (P -> Set) -> P

We can derive a contradiction.

One of the ways out of these paradoxes is only to allow strictly positive recursive types, which is what Agda and Coq choose. That means that if you declare:

data X : Set where
    MkX : F X -> X

That F must be a strictly positive functor, which means that X may never occur to the left of any arrow. So these types are strictly positive in X:

X * X
Nat -> X
X * (Nat -> X)

But these are not:

X -> Bool
(X -> Nat) -> Nat  -- this one is "positive", but not strictly
(X * Nat) -> X

So in short, no you can't represent your data type in Agda. You can use de Bruijn encoding to get a term type you can work with, but usually the evaluation function needs some sort of "timeout" (generally called "fuel"), e.g. a maximum number of steps to evaluate, because Agda requires all functions to be total. Here is an example due to @gallais that uses a coinductive partiality type to accomplish this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!