为归纳定义的类型查找(显示的)实现

Finding an implementation (of show) for an inductively defined type

以下片段来自 ():

tensor : Vect n Nat -> Type -> Type
tensor []        a = a
tensor (m :: ms) a = Vect m (tensor ms a)

我想定义以下内容:

mkStr : (Show a) => tensor shape a -> String
mkStr x = show x

但是这会产生以下错误:

Can't find implementation for Show (tensor shape a)

但是,在 REPL 上我可以 运行 "show [some tensor value...]"。为什么会这样,我该如何解决?

您没有显示 a,您显示的是 tensor shape a。因此,以下应该可以工作,您需要按以下方式编写类型:

mkStr : (Show (tensor shape a)) => tensor shape a -> String
mkStr x = show x