证明类型是 Functor - 推理错误?

Proving a type is a Functor - Inference error?

我有以下(简化的)数据类型,我正试图证明一个类型是函子。

  data T (a : Set) : Set where                                                                                                                                                                                                               
    D  : a → T a                                                                                                                                                                                                                             
                                                                                                                                                                                                                                             
  record Functor {a b : Set} (f : Set → Set ) : Set where                                                                                                                                                                                   
    field                                                                                                                                                                                                                                    
      fmap : (a → b) → f a → f b                                                                                                                                                                                                             
                                                                                                                                                                                                                                             
  functor_T : Functor T                                                                                                                                                                                                                      
  functor_T = record                                                                                                                                                                                                                         
    { fmap = fmap'                                                                                                                                                                                                                           
    }                                                                                                                                                                                                                                        
    where                                                                                                                                                                                                                                    
      fmap' : ∀ {a b} → (a → b) → T a → T b                                                                                                                                                                                                  
      fmap' f (D a) = D (f a)                                                                                                                                                                                                                           

但编译器突出显示 Functor 并提示以下行。

_a_22 : Set  [ at ... :10,15-22 ]                                                                                                                                                                    
_b_23 : Set  [ at ... :10,15-22 ]  

这是什么原因造成的?推理有问题吗?

目前您对 Functor 的定义指定您有运算符 fmap 用于两个 specific 类型 ab .大概您想要的是 fmap 适用于 所有 类型 ab,因此您需要以 [= 的类型对它们进行量化12=]:

  record Functor (f : Set → Set) : Set1 where                                                                                                                                                                                   
    field                                                                                                                                                                                                                                    
      fmap : {a b : Set} → (a → b) → f a → f b   

要使这项工作生效,您还需要将 Functor 本身的宇宙级别从 Set 更改为 Set1(参见 https://agda.readthedocs.io/en/latest/language/universe-levels.html)。

有了 Functor 的这个更改定义,您对 functor_T 的定义应该被接受而不做任何更改!

P.S.: 不建议在 Agda 的标识符中使用下划线,因为它们是为 mixfix 语法保留的,参见 https://agda.readthedocs.io/en/latest/language/mixfix-operators.html