Suppose I have an arbitrary module
module Foo where
foo :: Moo -> Goo
bar :: Car -> Far
baz :: Can -> Haz
where foo
, bar
, and baz
are correctly implemented, etc.
I'd like to reify this module into an automatically-generated data type and corresponding object:
import Foo (Moo, Goo, Car, Far, Can, Haz)
import qualified Foo
data FooModule = Foo
{ foo :: Moo -> Goo
, bar :: Car -> Far
, baz :: Can -> Haz
}
_Foo_ = Foo
{ foo = Foo.foo
, bar = Foo.bar
, baz = Foo.baz
}
Names must be precisely the same as the original module.
I could do this by hand, but that is very tedious, so I'd like to write some code to perform this task for me.
I'm not really sure how to approach such a task. Does Template Haskell provide a way to inspect modules? Should I hook into some GHC api? Or am I just as well off with a more ad-hoc approach such as scraping haddock pages?
haskell-src-exts
to parse the module source, then create your datatype from that and output a new source file? – Prognathous