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

前提是你 提交于 2021-01-27 21:50:49

问题


The following snippet was from (https://stackoverflow.com/a/37461290/2129302):

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

I'd like to define the following:

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

But instead this gives the following error:

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

However, on the REPL I can run "show [some tensor value...]". Why is this and what can I do to fix it?


回答1:


You're not showing a, you're showing tensor shape a. Thus, the following should work and you need to write type in the next way:

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


来源:https://stackoverflow.com/questions/47492744/finding-an-implementation-of-show-for-an-inductively-defined-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!