Skip to content

Instantly share code, notes, and snippets.

@elderica
Created November 27, 2011 09:17
Show Gist options
  • Save elderica/1397285 to your computer and use it in GitHub Desktop.
Save elderica/1397285 to your computer and use it in GitHub Desktop.
import System.Cmd (system)
import System.Environment (getArgs)
import Data.Text (breakOn, pack, unpack)
import Data.Maybe (fromJust)
compilers = [
(".hs", "ghc"),
(".c", "make")
]
main = do
args <- getArgs
if null args
then error "no input filename"
else do
let (mod, ext) = breakOn (pack ".") $ pack $ head args
let mod' = unpack mod
let ext' = unpack ext
if null ext'
then error "no extension"
else do
let compiler = fromJust $ lookup ext' compilers
let command = unwords [compiler, mod']
putStrLn command
system command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment