| Safe Haskell | None |
|---|
System.Command.QQ
Contents
Description
Quasiquoters for external commands
- sh :: QuasiQuoter
- shell :: FilePath -> QuasiQuoter
- interpreter :: FilePath -> QuasiQuoter
- quoter :: (String -> Q Exp) -> QuasiQuoter
- callCommand :: FilePath -> [String] -> String -> Q Exp
- class Eval r where
- class Embed a where
Quasiquoters
Quasiquoter for the default shell
"default" here means it uses value of SHELL environment variable
or /bin/sh if it is not set.
>>>[sh|echo "hi!"|] :: IO ExitCodehi! ExitSuccess>>>[sh|echo "hi!"|] :: IO String"hi!\n"
Haskell values can be embedded with Ruby-like syntax:
>>>let apples = 7>>>[sh|echo "#{apples} apples!"|] :: IO String"7 apples!\n"
Works only for expressions (obviously):
>>>return 3 :: IO [sh|blah|]<interactive>:116:16: Exception when trying to run compile-time code: this quasiquoter does not support splicing types Code: quoteType sh "blah"
shell :: FilePath -> QuasiQuoterSource
interpreter :: FilePath -> QuasiQuoterSource
Interpreter commands quasiquoter maker
"Interpreter" here means something that implements the following interface:
<INTERPRETER> -e <COMMAND>
e.g. perl, ruby, ghc, etc
Everything that applies to sh applies to interpreter
Customizations
quoter :: (String -> Q Exp) -> QuasiQuoterSource
Construct quasiquoter from function taking the string and producing Haskell expression.
Other kinds of quasiquoters (patterns, types or declarations quasiquoters) will fail in compile time
Arguments
| :: FilePath | Command path |
| -> [String] | Arguments that go to command before quasiquoter contents |
| -> String | Quasiquoter contents |
| -> Q Exp |
Construct Haskell expression for external command call
Different interesting return types for quasiquoters
Instances here mostly resemble the types of things in System.Process
Instances
| Eval (IO String) | Return only stdout of external process Does not care if external process failed.
|
| Eval (IO ()) | Most basic instance: nothing is known about what happened in external command
|
| (~ * s ExitCode, ~ * o String, ~ * e String) => Eval (IO (s, o, e)) | Return exit code, stdout, and stderr of external process
|
| Eval (IO ExitCode) | Return only exit code of external process
|
| (~ * i String, ~ * o (ExitCode, String, String)) => Eval (i -> IO o) | Return exit code, stdout, and stderr of external process
and consume stdin from supplied
|
Embed haskell values into external commands
I recommend using -XExtendedDefaultRules for modules
where you want to embed values, it would save for annoying
type annotations for numeric literals
embed . embed = embed
Instances
| Embed Char |
|
| Embed Double |
|
| Embed Float |
|
| Embed Int |
|
| Embed Int8 | |
| Embed Int16 | |
| Embed Int32 | |
| Embed Int64 | |
| Embed Integer |
|
| Embed Word | |
| Embed Word8 | |
| Embed Word16 | |
| Embed Word32 | |
| Embed Word64 | |
| Embed String |
|