如何使用Template Haskell生成的代码创建非TH包? [英] How to create a non-TH package from code generated using Template Haskell?

查看:155
本文介绍了如何使用Template Haskell生成的代码创建非TH包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个小包,为元组定义包装并添加实例,比如

  newtype Tuple2 a = Tuple2 {untuple2 ::(a,a)} 
派生(...)

tuple2 :: a - > a - > Tuple2 a
tuple2 = ...

实例Traversable Tuple2其中...
实例Foldable Tuple2其中...
实例Functor Tuple2其中...
实例Applicative Tuple2其中...

重复2到

生成的代码总是Haskell 98兼容,所以我想最终的结果是一个Haskell 98兼容包。 是否可以使用Template Haskell生成一段代码,并从中创建一个不使用TH本身的包?(如果可能,我宁愿采用自动化方式。)

有一些工具可供使用:
$ b


  • < a href =http://source.git-annex.branchable.com/?p=source.git;a=blob;f=Build/EvilSplicer.hs =nofollow> EvilSplicer ,书面通过 Joey Hess 发现之前

  • zeroth ,这似乎不再处于积极的发展状态。



    • 免责声明:我还没有尝试过这些。


      I'm making a small package that defines wrappers for tuples and adds instances form them, like

      newtype Tuple2 a = Tuple2 { untuple2 :: (a, a) }
        deriving (...)
      
      tuple2 :: a -> a -> Tuple2 a
      tuple2 = ...
      
      instance Traversable Tuple2 where ...
      instance Foldable Tuple2 where ...
      instance Functor Tuple2 where ...
      instance Applicative Tuple2 where ...
      

      This repeats from 2 to 15, so it looks like a job for Template Haskell.

      The generated code is always Haskell 98 compatible, so I'd like the final result to be a Haskell 98 compatible package too. Is it possible to generate a piece of code using Template Haskell and make a package from it that doesn't use TH itself? (I'd prefer an automated way, if possible.)

      解决方案

      There are tools for it:

      Disclaimer: I have not tried any of these myself.

      这篇关于如何使用Template Haskell生成的代码创建非TH包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆