Skip to content

Instantly share code, notes, and snippets.

@ilyar
Last active March 2, 2021 14:08
Show Gist options
  • Select an option

  • Save ilyar/73184f11e706e83c8d2d4ce95e2d426b to your computer and use it in GitHub Desktop.

Select an option

Save ilyar/73184f11e706e83c8d2d4ce95e2d426b to your computer and use it in GitHub Desktop.
Compiling and running in Haskell this invention of the bicycle there is already a runhaskell for this
#!/usr/bin/env bash
# Usage:
# ghc-run [ghc command-line-options-and-input-files] [-- programm-args]
# Sample:
# ghc-run main.hs
# ghc-run main.hs -- foo bar
# echo "foo bar" | ghc-run main.hs
set -o errexit
tmp=$(mktemp -d -t ci-XXXXXXXXXX)
file="${1%.*}"
delimiter="--"
args=()
params="${*}${delimiter}"
while [[ ${params} ]]; do
args+=( "${params%%"${delimiter}"*}" )
params=${params#*"${delimiter}"}
done
ghcArgs="-o ${tmp}/${file}"
ghcArgs+=" -hidir ${tmp}"
ghcArgs+=" -tmpdir ${tmp}"
ghcArgs+=" -odir ${tmp}"
ghcCMD="ghc ${ghcArgs} ${args[0]}"
runCMD="${tmp}/${file} ${args[1]}"
${ghcCMD}
${runCMD}
rm -rf "${tmp}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment