【发布时间】:2023-07-31 05:04:01
【问题描述】:
我已经定义了自己的Vect数据类型如下
data MyVect : (n : Nat) -> (t : Type) -> Type where
Nil : MyVect Z t
(::) : (x : t) -> (xs : MyVect n t) -> MyVect (S n) t
然后开始为数据类型实现Foldable接口
Foldable MyVect where
foldr = ?res2
但是在重新加载文件时,Idris 抱怨
When checking argument t to type constructor Prelude.Foldable.Foldable:
Type mismatch between
Nat -> Type -> Type (Type of MyVect)
and
Type -> Type (Expected type)
Specifically:
Type mismatch between
Nat
and
TypeUnification failure
摸了摸头,我猜我可以通过编写来满足 Idris 对类型构造函数的要求
Foldable (MyVect n) where
foldr = ?res2
然后我开始思考“如果我定义 MyVect 并翻转类型参数会怎样?...”
data MyVect : (t : Type) -> (n : Nat) -> Type where
Nil : MyVect t Z
(::) : (x : t) -> (xs : MyVect t n) -> MyVect t (S n)
是否可以为MyVect 的“参数翻转”版本实现可折叠接口? (以及如何?)
【问题讨论】:
标签: idris