Skip to content

Instantly share code, notes, and snippets.

@snoyberg
Created June 28, 2015 08:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snoyberg/b28f0b7dc115dd190b69 to your computer and use it in GitHub Desktop.
Save snoyberg/b28f0b7dc115dd190b69 to your computer and use it in GitHub Desktop.
#!/usr/bin/env runstack
-- stack --resolver lts-2.9 --install-ghc runghc --package turtle
{-# LANGUAGE OverloadedStrings #-}
import Turtle
main :: IO ()
main = echo "Hello World!"
module Main where
import System.Environment
import System.Exit
import System.Process
main :: IO ()
main = do
args <- getArgs
fp <-
case args of
[fp] -> return fp
[] -> error "Must provide a filename"
_ -> error "Must provide exactly one filename"
ls <- fmap lines $ readFile fp
let stackArgs = takeArgs $ dropShebang ls
let cp = proc "stack" $ stackArgs ++ [fp]
(Nothing, Nothing, Nothing, ph) <- createProcess cp
waitForProcess ph >>= exitWith
dropShebang :: [String] -> [String]
dropShebang (('#':'!':_):rest) = rest
dropShebang x = x
takeArgs :: [String] -> [String]
takeArgs [] = []
takeArgs (x:_) =
case words x of
"--":"stack":rest -> rest
_ -> []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment