I have a toy program:
$ cat a.hs
main = putStrLn "Toy example"
$ runghc a.hs
Toy example
Let's add some Template Haskell to it:
$ cat b.hs
{-# LANGUAGE TemplateHaskell #-}
id [d|
main = putStrLn "Toy example"
|]
$ runghc b.hs
b.hs:3:0: parse error (possibly incorrect indentation)
Right then, let's fix the indentation:
$ cat c.hs
{-# LANGUAGE TemplateHaskell #-}
id [d|
main = putStrLn "Toy example"
|]
$ runghc c.hs
Toy example
A single space is enough, but I do have to indent both trailing lines.
Can I avoid having to indent most of my module? (My Real Modules have much more than a single line of code.) (And without using { ; ; }
notation?)
I do want all of the module declarations to be captured in the quotation — in normal code I can replace (...)
with $ ...
, is there some equivalent of [d|...|]
that would let me avoid the close brackets and also the indenting?
Or is there some way module A can say that the top-level declarations of any module B that A is imported into are automatically processed by a function A exports?
Notes:
- The Template Haskell in my Real Program is more complex than
id
— it scans the declarations for variable names that startprop_
, and builds a test suite containing them. Is there some other pure Haskell way I could do this instead, without directly munging source files? - I'm using GHC v6.12.1. When I use GHC v7.0.3, the error for b.hs is reported for a different location —
b.hs:3:1
— but the behaviour is otherwise identical.