简体   繁体   中英

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:

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. 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. Any pointers or explanation that anyone could provide would be greatly appreciated!

Thanks, Bill


Here's the Agda code that generates thin its entirety:

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! This sort of error indicates an unsolved metavariable, which means that Agda has failed to infer an implicit argument. 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. To fix this, specify the level: {abc : Set} .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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