简体   繁体   English

阿格达的“严格积极”

[英]“Strictly positive” in Agda

I'm trying to encode some denotational semantics into Agda based on a program I wrote in Haskell. 我正在尝试根据我在Haskell中编写的程序将一些指称语义编码到Agda中。

data Value = FunVal (Value -> Value)
           | PriVal Int
           | ConVal Id [Value]
           | Error  String

In Agda, the direct translation would be; 在阿格达,直接翻译将是;

data Value : Set where
    FunVal : (Value -> Value) -> Value
    PriVal : ℕ -> Value
    ConVal : String -> List Value -> Value
    Error  : String -> Value

but I get an error relating to the FunVal because; 但是我得到了与FunVal有关的错误,因为;

Value is not strictly positive, because it occurs to the left of an arrow in the type of the constructor FunVal in the definition of Value. 值并非严格为正,因为它出现在Value定义中构造函数FunVal类型中箭头的左侧。

What does this mean? 这是什么意思? Can I encode this in Agda? 我可以用Agda编码吗? Am I going about it the wrong way? 我是以错误的方式去做的吗?

Thanks. 谢谢。

HOAS doesn't work in Agda, because of this: HOAS在Agda中不起作用,因为:

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 ww gives you apply ww back again. 现在,注意评估apply ww让你再次apply ww The term apply ww has no normal form, which is a no-no in agda. apply ww这个术语没有正常形式,这在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. 解决这些悖论的方法之一只是允许严格正面的递归类型,这就是Agda和Coq选择的方式。 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. F必须是严格正的函子,这意味着X可能永远不会出现在任何箭头的左侧。 So these types are strictly positive in X : 所以这些类型在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. 简而言之,您无法在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"), eg a maximum number of steps to evaluate, because Agda requires all functions to be total. 您可以使用de Bruijn编码来获得可以使用的术语类型,但通常评估函数需要某种“超时”(通常称为“燃料”),例如要评估的最大步骤数,因为Agda需要所有函数总计。 Here is an example due to @gallais that uses a coinductive partiality type to accomplish this. 以下是 @gallais使用coinductive偏好类型来实现此目的的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM