Incerteza
Incerteza

Reputation: 34874

Preprocessor in Haskell

I want to generate import qualified Aaaa.Bbb.Ccc as Ccc automatically at compile time.

Is there any way to do that? Maybe by Template Haskell or anyhow else with any extention? I think it's similar to macroses in C and the function $(...) in Tempalte Haskell.

Upvotes: 1

Views: 831

Answers (1)

sapanoia
sapanoia

Reputation: 789

If what you are trying to achieve is shortening your import list, you may try the following trick. Create a new module (Foo):

module Foo (module X) where
import A as X
import B as X
import C as X

Then import this module to get all members of A, B, and C:

module Bar where
import qualified Foo as X

This way you can combine modules which are commonly used throughout your project.

If you still need to auto-generate the imports, at least you only need to generate module Foo, but not Bar. So the automatically and manually generated code is separated cleanly.

Upvotes: 3

Related Questions