首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用注释和漂亮的打印机

使用注释和漂亮的打印机
EN

Stack Overflow用户
提问于 2019-11-21 01:59:47
回答 1查看 42关注 0票数 3

我用的是漂亮的打印机Data.Text.Prettyprint.Doc。现在,我想以不同的方式设置输出的样式,并认为语义注释的想法非常适合这里。考虑下面的例子

代码语言:javascript
运行
复制
{-# LANGUAGE OverloadedStrings #-}

import Data.Text.Prettyprint.Doc

data Foo = X | Y
data Ann = AnnX | AnnY

instance Pretty Foo where
  pretty X = "[" <+> (annotate AnnX "X was here") <+> "]"
  pretty Y = "nothing"

此操作将失败,并显示如下错误

代码语言:javascript
运行
复制
/Example.hs:14:14: error:
    • Couldn't match type ‘ann’ with ‘Ann’
      ‘ann’ is a rigid type variable bound by
        the type signature for:
          pretty :: forall ann. Foo -> Doc ann
        at /Example.hs:14:3-8
      Expected type: Doc ann
        Actual type: Doc Ann
    • In the expression: "[" <+> (annotate AnnX "X was here") <+> "]"
      In an equation for ‘pretty’:
          pretty X = "[" <+> (annotate AnnX "X was here") <+> "]"
      In the instance declaration for ‘Pretty Foo’
    • Relevant bindings include
        pretty :: Foo -> Doc ann
          (bound at /Example.hs:14:3)
   |
14 |   pretty X = "[" <+> (annotate AnnX "X was here") <+> "]"
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

我几乎不明白。我的目的是注释文档,后来我想为注释想出不同的驱动程序。例如,我希望有一个将文档X was here映射到<strong>X was here</strong>的驱动程序,另一个将文档映射到<i>X was here</i>的驱动程序。也许我错误地理解了整个注释部分。有没有人能给我一些启发,或者给我提供一个例子的链接?

EN

回答 1

Stack Overflow用户

发布于 2019-11-21 05:59:00

Pretty类型类需要可以处理任何类型注释的东西。在您的例子中,它们只适用于您的Ann类型。这样的方法必须是它自己的东西,因为它对pretty是无效的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58960669

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档