Skip to content

Script interpreter

Chris Wilson edited this page Nov 1, 2018 · 10 revisions

This page has mostly been superseded by the stack guide. We may remove this content in the future, but it is kept for now.

You can use stack as a script interpreter. Here is an example that uses the turtle package:

#!/usr/bin/env stack
-- stack --resolver lts-9.13 --install-ghc runghc --package turtle
{-# LANGUAGE OverloadedStrings #-}
import Turtle
main = echo "Hello World!"

Set the executable bit on the script, and then you can run it as a regular command (on Windows, you will have to run stack <script>.hs).

The first line is the usual "shebang" to use stack as a script interpreter. The second line, which is required, provides additional options to stack (due to the common limitation of the "shebang" line only being allowed a single argument). In this case, the options tell stack to use the lts-9.13 resolver, automatically install GHC if it is not already installed, and ensure the turtle package is available.

You can’t perform that action at this time.