如何使用Template Haskell生成的代码创建非TH包? [英] How to create a non-TH package from code generated using Template Haskell?
问题描述
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
免责声明:我还没有尝试过这些。
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:
- EvilSplicer, written by Joey Hess before he discovered
- zeroth, which does not seem to be in active development any more.
Disclaimer: I have not tried any of these myself.
这篇关于如何使用Template Haskell生成的代码创建非TH包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!