Last active
April 30, 2019 11:06
Star
You must be signed in to star a gist
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 #-} | |
{-# OPTIONS_GHC -Wall #-} | |
module Compiler where | |
import Language.Haskell.TH | |
type QTExp a = Q (TExp a) | |
idM :: Monoid m => m -> m | |
idM act = act | |
{- | |
iter :: Monoid m => QTExp (IO m) -> QTExp (IO m) | |
iter yld = [|| let x = idM (($$(yld) >> x)) | |
in x ||] | |
runQuery :: QTExp (IO ()) | |
runQuery = iter (iter [|| return () ||]) | |
-} | |
{- | |
iter :: forall m . Monoid m => QTExp (IO m) | |
iter = [|| let x = idM (let x1 = idM (return () >> x1) in x1) >> x | |
in x ||] | |
-} | |
{- | |
iter :: forall m . Monoid m => QTExp (IO m) | |
iter = [|| let x = idM (let x1 = idM (return () >> x1) in x1) >> x | |
in x ||] | |
-} | |
tenM :: Monoid m => QTExp (IO m) -> QTExp (IO m) | |
tenM dot = [|| let x 0 = putStr "\n" >> return mempty | |
x i = $$dot >> x (i - 1) | |
in x 9 ||] | |
printDots :: QTExp (IO ()) | |
printDots = tenM (tenM [|| putStr "." ||]) | |
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.printDots) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment