我正在尝试破译有关级别的错误消息。在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
到目前为止,太好了。现在,当我尝试在Agda中定义类似函数时,我收到一条关于我不理解的级别的错误消息。具体来说,我收到此错误消息:
_a_41 : .Agda.Primitive.Level [ at ...snip.../MinimalStream.agda:20,34-35 ]
_b_42 : .Agda.Primitive.Level [ at ...snip.../MinimalStream.agda:20,34-35 ]
似乎在抱怨twist类型声明中类型变量a和b的级别,但是我不确定我是否理解问题所在。任何人都可以提供的任何指示或解释将不胜感激!
谢谢, 比尔
以下是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') }
答案 0 :(得分:0)
欢迎堆栈溢出!这种错误表示未解决的元变量,这意味着Agda无法推断出隐式参数。错误消息指示该元变量的(自动生成的)名称及其类型。在这种情况下,问题可能与{a, b, c}
中的twist
类型有关:尚不清楚它们应位于哪个级别。要解决此问题,请指定级别:{a b c : Set}
。