【发布时间】:2013-05-13 08:41:16
【问题描述】:
我正在制作一个小包,它为元组定义包装器并从它们中添加实例,例如
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 ...
这从 2 重复到 15,所以它看起来像是 Template Haskell 的工作。
生成的代码始终与 Haskell 98 兼容,因此我希望最终结果也是与 Haskell 98 兼容的包。 是否可以使用 Template Haskell 生成一段代码并从中制作一个不使用 TH 本身的包?(如果可能,我更喜欢自动化的方式。)
【问题讨论】:
标签: haskell tuples template-haskell