Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to avoid extra indentation in Template Haskell declaration quotations?
    primarykey
    data
    text
    <p>I have a toy program:</p> <pre><code>$ cat a.hs main = putStrLn "Toy example" $ runghc a.hs Toy example </code></pre> <p>Let's add some Template Haskell to it:</p> <pre><code>$ cat b.hs {-# LANGUAGE TemplateHaskell #-} id [d| main = putStrLn "Toy example" |] $ runghc b.hs b.hs:3:0: parse error (possibly incorrect indentation) </code></pre> <p>Right then, let's fix the indentation:</p> <pre><code>$ cat c.hs {-# LANGUAGE TemplateHaskell #-} id [d| main = putStrLn "Toy example" |] $ runghc c.hs Toy example </code></pre> <p>A single space is enough, but I do have to indent both trailing lines.</p> <p>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 <code>{ ; ; }</code> notation?)</p> <p>I do want <em>all</em> of the module declarations to be captured in the quotation — in normal code I can replace <code>(...)</code> with <code>$ ...</code>, is there some equivalent of <code>[d|...|]</code> that would let me avoid the close brackets and also the indenting?</p> <p>Or is there some way module <em>A</em> can say that the top-level declarations of any module <em>B</em> that <em>A</em> is imported into are automatically processed by a function <em>A</em> exports?</p> <p>Notes:</p> <ol> <li>The Template Haskell in my Real Program is more complex than <code>id</code> — it scans the declarations for variable names that start <code>prop_</code>, and builds a test suite containing them. Is there some other pure Haskell way I could do this instead, without directly munging source files?</li> <li>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 — <code>b.hs:3:1</code> — but the behaviour is otherwise identical.</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload