简体   繁体   English

Agda级别错误消息的含义:…:.Agda.Primitive.Level

[英]Meaning of Agda level error message: … : .Agda.Primitive.Level

I'm trying to decipher an error message concerning levels. 我试图破译有关级别的错误消息。 In Haskell, I can write the following stream function, twist, in a straightforward fashion: 在Haskell中,我可以用简单的方式编写以下stream函数,twist:

data Stream a = a :> Stream a
twist :: (a -> (b , (Either a c))) -> (c -> (b , (Either a c))) -> (Either a c) -> Stream b
twist lt rt (Left a) = b :> twist lt rt ac
   where
     (b , ac) = lt a
twist lt rt (Right c) = b :> twist lt rt ac
   where
     (b , ac) = rt c

So far, so good. 到现在为止还挺好。 Now, when I attempt to define the analogous function in Agda, I get an error message about levels that I don't understand. 现在,当我尝试在Agda中定义类似函数时,我收到一条关于我不理解的级别的错误消息。 Specifically, I get this error message: 具体来说,我收到此错误消息:

_a_41 : .Agda.Primitive.Level  [ at ...snip.../MinimalStream.agda:20,34-35 ]
_b_42 : .Agda.Primitive.Level  [ at ...snip.../MinimalStream.agda:20,34-35 ]

It seems to be complaining about the level of type variables a and b in the type declaration of twist, but I am not sure I understand what the problem is. 似乎在扭曲类型声明中抱怨类型变量a和b的级别,但是我不确定我明白问题出在哪里。 Any pointers or explanation that anyone could provide would be greatly appreciated! 任何人都可以提供的任何指示或解释将不胜感激!

Thanks, Bill 比尔,谢谢


Here's the Agda code that generates thin its entirety: 这是可简化整体的Agda代码:

module MinimalStream where

open import Data.Product using (_×_; _,_; proj₁)
open import Data.Sum -- using (_⊎_)

case_of_ : ∀ {a b} {A : Set a} {B : Set b} → A → (A → B) → B
case x of f = f x

record Stream A : Set where
  coinductive
  field headStr : A
        tailStr : Stream A
open Stream; S = Stream

-- standard kinds of stream functions work as expected.
unzip₁ : ∀ {a b : Set} → Stream (a × b) → Stream a
headStr (unzip₁ sab) = proj₁ (headStr sab)
tailStr (unzip₁ sab) = unzip₁ (tailStr sab)

twist : ∀ {a b c} → (a → (b × (a ⊎ c))) → (c → (b × (a ⊎ c))) → (a ⊎ c) → Stream b
headStr (twist lt rt (inj₁ a)) = case lt a of
                                    λ { (b , (inj₁ _)) → b ;
                                        (b , (inj₂ _)) → b }
headStr (twist lt rt (inj₂ c)) = case rt c of
                                    λ { (b , (inj₁ _)) → b ;
                                        (b , (inj₂ _)) → b }
tailStr (twist lt rt (inj₁ a)) = case lt a of
                                    λ { (_ , (inj₁ a')) → twist lt rt (inj₁ a') ;
                                        (_ , (inj₂ c))  → twist lt rt (inj₂ c)  }
tailStr (twist lt rt (inj₂ c)) = case rt c of
                                    λ { (_ , (inj₁ a))  → twist lt rt (inj₁ a) ;
                                        (_ , (inj₂ c')) → twist lt rt (inj₂ c')  }

Welcome to Stack Overflow! 欢迎来到Stack Overflow! This sort of error indicates an unsolved metavariable, which means that Agda has failed to infer an implicit argument. 这种错误表示未解决的元变量,这意味着Agda未能推断出隐式参数。 The error message indicates the metavariable's (autogenerated) name and its type. 错误消息指示元变量(自动生成)名称及其类型。 In this case, the issue is probably with the types {a, b, c} in twist : It is unclear which level these should be at. 在这种情况下,问题可能与类型{a, b, c} twist :尚不清楚它们应位于哪个级别。 To fix this, specify the level: {abc : Set} . 要解决此问题,请指定级别: {abc : Set}

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

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