Idris接口发出奇怪的错误消息

Rod*_*iro 6 idris

我正在尝试使用Idris接口实现一个简单的代数结构层次结构.代码如下:

module AlgebraicStructures

-- definition of some algebraic structures in terms of type classes

%access public export

Associative : {a : Type} -> (a -> a -> a) -> Type
Associative {a} op = (x : a) -> 
                     (y : a) ->
                     (z : a) ->
                     (op x (op y z)) = (op (op x y) z)

Identity : {a : Type} -> (a -> a -> a) -> a -> Type
Identity op v = ((x : a) -> (op x v) = x, 
                 (x : a) -> (op v x) = x)                 


Commutative : {a : Type} -> (a -> a -> a) -> Type
Commutative {a} op = (x : a) ->
                     (y : a) ->
                     (op x y) = (op y x)


infixl 4 <**>

interface IsMonoid a where
  empty  : a
  (<**>) : a -> a -> a 
  assoc  : Associative (<**>) 
  ident  : Identity (<**>) empty


interface IsMonoid a => IsCommutativeMonoid a where
  comm : Commutative (<**>)
Run Code Online (Sandbox Code Playgroud)

但是,Idris给出了这个奇怪的错误信息:

When checking type of constructor of AlgebraicStructures.IsCommutativeMonoid:
Can't find implementation for IsMonoid a
Run Code Online (Sandbox Code Playgroud)

我相信Idris接口就像Haskell的类型类一样.在Haskell中,它应该工作.我做傻事吗?

pdx*_*eif 6

我相信它可能会抱怨,因为我不知道a在表达式中有任何约束Commutative (<**>)- 所以它不知道你可以调用<**>那种类型.明确指定a似乎对我有用Commutative {a} (<**>)- 我希望这意味着a来自接口签名的范围可用于显式传递给其他类型.