Idris 接口的奇怪错误消息
Strange error message with Idris interfaces
我正在尝试使用 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 (<**>)
但是,Idris 给出了这个奇怪的错误消息:
When checking type of constructor of AlgebraicStructures.IsCommutativeMonoid:
Can't find implementation for IsMonoid a
我相信 Idris 接口的工作方式类似于 Haskell 的类型 类。在 Haskell 中,它应该可以工作。我在做什么傻事吗?
我相信它可能在抱怨,因为我不知道在表达式 Commutative (<**>)
中有什么限制了 a
- 所以它不知道你可以调用 <**>
在那个类型上。
明确指定 a
似乎对我有用 - Commutative {a} (<**>)
- 我希望这意味着接口签名中的 a
在范围内并且可用于显式传递给其他类型。
我正在尝试使用 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 (<**>)
但是,Idris 给出了这个奇怪的错误消息:
When checking type of constructor of AlgebraicStructures.IsCommutativeMonoid:
Can't find implementation for IsMonoid a
我相信 Idris 接口的工作方式类似于 Haskell 的类型 类。在 Haskell 中,它应该可以工作。我在做什么傻事吗?
我相信它可能在抱怨,因为我不知道在表达式 Commutative (<**>)
中有什么限制了 a
- 所以它不知道你可以调用 <**>
在那个类型上。
明确指定 a
似乎对我有用 - Commutative {a} (<**>)
- 我希望这意味着接口签名中的 a
在范围内并且可用于显式传递给其他类型。