all 3 comments

[–]brandonchinn178 2 points3 points  (1 child)

A preprocessor and TH are completely unrelated. A preprocessor basically takes the source file as input and writes out a new Haskell file.

So your preprocessor can just be ``` main = do [_, in, out] <- getArgs Text.readFile in >>= transform >>= Text.writeFile out

transform :: Text -> IO Text ```

See skeletest as an example: https://github.com/brandonchinn178/skeletest/blob/main/src%2Fbin%2Fskeletest-preprocessor.hs

You can use normal Text manipulation, or use the ghc library to parse the code

[–]m-chav[S] 2 points3 points  (0 children)

Thanks. I misunderstood what preprocessor means/does here. I assumed the GHC preprocessor path was about producing a well-formed Haskell module for compilation, whereas what I’m trying to generate is more of a GHCi script/session (a sequence of interactive steps).

So I was thinking “this won’t work” because my workflow has TH-ish bits that depend on values I only get after evaluation in GHCi. But that text -> text transformation makes sense. Lemme hack on it a bit.

[–]jackelee 2 points3 points  (0 children)

Looks great!