runghc examples
a somewhat lengthy ticket closed Jul 4, 2022
Recently I took another look at the runghc code.
utils/runghc/Main.hs
utils/runghc/runghc.cabal.in
This could be rewritten not using literate Haskell.
$ sed 17q ghc/utils/runghc/Main.hs
{-# LANGUAGE CPP #-}
#include <ghcplatform.h>
-----------------------------------------------------------------------------
--
-- (c) The University of Glasgow, 2004
--
-- runghc program, for invoking from a #! line in a script. For example:
--
-- script.lhs:
-- #!/usr/bin/env runghc
-- > main = putStrLn "hello!"
--
-- runghc accepts one flag:
--
-- -f <path> specify the path
--
-- -----------------------------------------------------------------------------
$
rewrite
- -- script.lhs:
+ -- script.hs:
-- #!/usr/bin/env runghc
- -- > main = putStrLn "hello!"
+ -- main = putStrLn "hello!"
This file looks as if it has an improperly written here document.
perhaps it's just an errant redirect symbol
$ ed -s ghc/utils/runghc/runghc.cabal.in <<<'10,20p'
@runghc@ is a small wrapper program around GHC which allows the compiler
to be used as a UNIX-style script interpreter. For instance,
.
@
$ cat > Hi.hs
\#!/usr/bin/env runghc
main = putStrLn "hello!"
$ chmod u+x Hi.hs
$ ./Hi.hs
hello!
@
$
A properly written here document in a shell.
$ cat <<EOF > Hi.hs
> #!/usr/bin/env runghc
> main = putStrLn "hello!"
> EOF
$
The runghc.cabal.in
extract appears to escape the #
character.
Is escaping characters in @ @
sections documented somewhere?