Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Data.Comp.Variables中Subst的Haskell打印机_Haskell_Types_Functional Programming_Type Inference_Unification - Fatal编程技术网

Data.Comp.Variables中Subst的Haskell打印机

Data.Comp.Variables中Subst的Haskell打印机,haskell,types,functional-programming,type-inference,unification,Haskell,Types,Functional Programming,Type Inference,Unification,我有一个函数,返回此库中定义的Subst: 我正在尝试打印返回值。打印机应显示从变量到术语的映射 当我尝试打印结果时,我得到: • No instance for (Show (Cxt NoHole CTypeF ())) arising from a use of ‘print’ • In the expression: (print subst) 我想这意味着我必须安装一台打印机。我知道当它是一个用户定义的类时,我可以做“派生显示”。有人能指出我该怎么打印这个吗

我有一个函数,返回此库中定义的
Subst

我正在尝试打印返回值。打印机应显示从变量到术语的映射

当我尝试打印结果时,我得到:

  • No instance for (Show (Cxt NoHole CTypeF ()))
        arising from a use of ‘print’
  • In the expression: (print subst)
我想这意味着我必须安装一台打印机。我知道当它是一个用户定义的类时,我可以做“派生显示”。有人能指出我该怎么打印这个吗

另外,这是我的CTypeF结构

data CTypeF a 
    = CVarF Int 
    | CArrF a a
    | CIntF
    | CBoolF
    deriving (Eq, Data, Functor, Foldable, Traversable, Show)
它派生了show,因此我认为问题不在这里。

有一个
show
实例,但它要求其
f
参数有一个的实例

因此,您需要使
CTypeF
具有
ShowF
的实例。为此,可以使用模板Haskell

$(makeShowF ''CTypeF)

Cxt
没有
Show
实例,因此无论您给出什么参数,都无法打印。对不起,我是haskell的新手,我不理解您的观点。我已经知道缺少该实例,我的问题是如何实现它。那么你是说你不能定义一个实例吗?@Lana应该仍然可以为
Ctx
定义一个
Show
实例。它看起来像是
实例(Show(f(Ctx h f a)),Show a)=>Show(Ctx h f a),其中Show(Term x)=Show x Show(Hole a)=Show a
。请注意,这是未经测试的,因此可能无法按您希望的方式工作,但
Show
实例将按照以下方式运行。
$(makeShowF ''CTypeF)