Haskell -- 如何使用新的 4 参数准引用器

发布于 2024-11-26 15:08:55 字数 228 浏览 6 评论 0原文

看起来准引用语法已更改为现在接受 4 个参数 [ 链接]。有人用过吗?谢谢。我只想构建一些非常非常简单的东西,网络上的示例现在不起作用。

提前致谢。

It looks like the quasi quoter syntax has changed to now accept 4 arguments [ link ]. Has anyone used it yet? Thanks. I just want to build something really really simple, and the examples on the web won't work now.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

相思碎 2024-12-03 15:08:55

QuasiQuoter 的每个部分只是一个函数,它接受一个字符串(准引用的内容)并在 Q monad 中返回一个适当的值。如果您的准引用器不支持在其中某些上下文中使用,则只需返回错误,例如:

someQuoter = QuasiQuoter { quoteType = const $ fail "type context unsupported" 
                         , -- etc ...
                         }

fail 方法调用report True,这会产生编译器错误。这几乎是正确的行为。

Each piece of the QuasiQuoter is just a function that takes a string (the content of the quasi-quote) and returns an appropriate value in the Q monad. If your quasiquoter doesn't support being used in some of those contexts, just return an error, e.g.:

someQuoter = QuasiQuoter { quoteType = const $ fail "type context unsupported" 
                         , -- etc ...
                         }

The fail method calls report True, which produces a compiler error. This is pretty much the correct behavior.

阳光下慵懒的猫 2024-12-03 15:08:55

基本上,变化是您现在可以为类型和声明(除了表达式和模式之外)创建准引号。

如果您不想使用类型/声明字段,则可以将它们设置为错误“此准引用器不支持拼接类型/声明”。

Basically the changes are that you can now make quasiquoters for types and declarations (in addition to expressions and patterns).

It should be fine to set the type/declaration fields to error "This quasiquoter doesn't support splicing types/declarations" if you don't want to use them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文