Skip to content

Running a Stack Project

To run your project, we use

Shell
$ stack run
someFunc

If some source code files were changed since the last stack build or stack run command, then this compiles our project before running it. Otherwise, it just runs it.

Our hello-world project was set up by stack new just so it can be compiled and run, but it obviously doesn't do anything useful. The Lib.hs file contains a function someFunc that prints its name:

src/Lib.hs
module Lib
    ( someFunc
    ) where

someFunc :: IO ()
someFunc = putStrLn "someFunc"

and the Main.hs file imports Lib and contains a main function that calls someFun:

app/Main.hs
module Main (main) where

import Lib

main :: IO ()
main = someFunc

Hence the rather underwhelming output someFunc when running our program using stack run.

In your project, your program will take command line arguments. The arguments given to stack run are arguments for stack itself, not for your program. To tell stack where its own list of arguments ends and where the list of arguments to be passed to your program start, you need to use two dashes:

stack run -- <arguments to be passed to your program>