Skip to content

Instantly share code, notes, and snippets.

@mpickering
Created October 30, 2018 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpickering/f04a613bb5e20c241c5b91c2f38b8f06 to your computer and use it in GitHub Desktop.
Save mpickering/f04a613bb5e20c241c5b91c2f38b8f06 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wall #-}
module Compiler where
import Language.Haskell.TH
type QTExp a = Q (TExp a)
fix :: (a -> a) -> a
fix f = let x = f x in x
while ::
forall m . Monoid m =>
QTExp (IO m -> IO m) -> QTExp (IO m)
while b = [|| fix (\r -> whenM @(IO m) ($$b r)) ||]
whenM :: Monoid m => m -> m
whenM _ = mempty
execOp :: forall m . Monoid m => QTExp (IO m)
execOp = while [|| \r -> $$(while @m [|| id ||]) >> r ||]
runQuery :: QTExp (IO ())
runQuery = execOp
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -ddump-splices #-}
module Test where
import qualified Compiler as C
main :: IO ()
main = do
$$(C.runQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment