How to create a non-TH package from code created using a Haskell template?

I am making a small package that defines wrappers for tuples and adds instances of them, e.g.

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 the Haskell template.

The generated code is always compatible with Haskell 98, so I want the end result to be also compatible with the Haskell 98 package. Is it possible to generate a code fragment using the Haskell template and make a package out of it that does not use TH? (I would prefer an automatic way, if possible.)

+7
source share
2 answers

There are tools for this:

Disclaimer: I myself have not tried any of them.

+3
source

You can always simply write a Haskell program that outputs the Haskell source code as a regular text file. Then you can compile it like any other file.

What this does not give you, of course:

  • Syntax check (Ie, the code you generate may contain syntax errors.)
  • The ability to verify hand-written code has already been compiled.
  • Ability to use other GHC functions, such as type inference.
+2
source

All Articles