Created
October 30, 2018 11:28
-
-
Save mpickering/f04a613bb5e20c241c5b91c2f38b8f06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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