Quasiquoters for external commands

Latest on Hackage:

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow to host generated Haddocks.

BSD3 licensed by Matvey Aksenov


Hackage Build Status Build Status

>>> import System.Command.QQ
>>> putStr =<< unlines . reverse . lines <$> [sh|cowsay "Hello, I am command-qq!"|]
                ||     ||
                ||----w |
            (__)\       )\/\
         \  (oo)\_______
        \   ^__^
< Hello, I am command-qq! >


% cabal install command-qq


Quasiquotation syntax for external interpreters

>>> [sh_| echo hello world! |]
hello world!

Custom quasiquoters

ghci = quoter $ callCommand "ghc" ["-ignore-dot-ghci", "-e"]

Then you can use ghci in ghci!

>>> [ghci| putStrLn "hello world!" |] :: IO ()
hello world!

For more examples, see System.Command.QQ.Predef

Haskell values embedding

Let's define Embed instance for a custom data type:

data Bang = Bang

instance Embed Bang where
  embed Bang = "!"

Then you can use variables of Bang type in quoted strings!

>>> [sh_| echo hello#{Bang} |]
>>> let bang = Bang in [sh_| echo hello#{bang} |]

Note, command-qq does not support full Haskell in embeddings, only variables/constructors names and literals


See examples/CommandT.hs


  • Added another way to avoid variable expansion (\\#{foo} is replaced with #{foo})

  • Exported substituteVars

  • Added a bunch of predefined quasiquoters to System.Command.QQ.Predef

  • Added Embed instances for Data.Text.Text and Data.Text.Lazy.Text

  • Added sh_ quasiquoter to avoid type annotations for trivial quotes

  • Moved Eval onto Text to speed I/O up.

  • Added support for embedding literals and constructors with no arguments

  • Mored Embed instances

Depends on 4 packages:
Used by 1 package:
comments powered byDisqus