Created
June 28, 2015 08:32
-
-
Save snoyberg/b28f0b7dc115dd190b69 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env runstack | |
-- stack --resolver lts-2.9 --install-ghc runghc --package turtle | |
{-# LANGUAGE OverloadedStrings #-} | |
import Turtle | |
main :: IO () | |
main = echo "Hello World!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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