2
2
3
3
# Stack's script interpreter
4
4
5
- Stack also offers a very useful feature for running files: a script interpreter.
6
- For too long have Haskellers felt shackled to bash or Python because it's just
7
- too hard to create reusable source-only Haskell scripts. Stack attempts to solve
5
+ Stack offers a very useful feature for running files: a script interpreter. For
6
+ too long have Haskellers felt shackled to bash or Python because it's just too
7
+ hard to create reusable source-only Haskell scripts. Stack attempts to solve
8
8
that.
9
9
10
10
You can use ` stack <file_name> ` to execute a Haskell source file. Usually, the
@@ -19,7 +19,7 @@ An example will be easiest to understand. Consider the Haskell source file
19
19
20
20
~~~ haskell
21
21
#!/usr/bin/env stack
22
- -- stack script --resolver lts-19.28 --package turtle
22
+ -- stack script --resolver lts-20.4 --package turtle
23
23
{-# LANGUAGE OverloadedStrings #-}
24
24
import Turtle (echo )
25
25
main = echo " Hello World!"
@@ -78,10 +78,10 @@ able to reuse everything already built).
78
78
79
79
The second line of the source code is the Stack interpreter options comment. In
80
80
this example, it specifies the ` stack script ` command with the options of a
81
- LTS Haskell 19.28 snapshot (` --resolver lts-19.28 ` ) and ensuring the
81
+ LTS Haskell 20.4 snapshot (` --resolver lts-20.4 ` ) and ensuring the
82
82
[ ` turtle ` package] ( https://hackage.haskell.org/package/turtle ) is available
83
83
(` --package turtle ` ). The version of the package will be that in the specified
84
- snapshot (` lts-19.28 ` provides ` turtle-1.5.25 ` ).
84
+ snapshot (` lts-20.4 ` provides ` turtle-1.5.25 ` ).
85
85
86
86
## Arguments and interpreter options and arguments
87
87
@@ -116,7 +116,7 @@ For example, the command `stack MyScript.hs arg1 arg2` with `MyScript.hs`:
116
116
~~~ haskell
117
117
#!/usr/bin/env stack
118
118
{- stack script
119
- --resolver lts-19.28
119
+ --resolver lts-20.4
120
120
--
121
121
+RTS -s -RTS
122
122
-}
@@ -132,7 +132,7 @@ main = do
132
132
is equivalent to the following command at the command line:
133
133
134
134
~~~ text
135
- stack script --resolver lts-19.28 -- MyScript.hs arg1 arg2 +RTS -s -RTS
135
+ stack script --resolver lts-20.4 -- MyScript.hs arg1 arg2 +RTS -s -RTS
136
136
~~~
137
137
138
138
where ` +RTS -s -RTS ` are some of GHC's
@@ -161,7 +161,7 @@ space separated list. For example:
161
161
~~~ haskell
162
162
#!/usr/bin/env stack
163
163
{- stack script
164
- --resolver lts-19.28
164
+ --resolver lts-20.4
165
165
--package turtle
166
166
--package "stm async"
167
167
--package http-client,http-conduit
@@ -170,7 +170,8 @@ space separated list. For example:
170
170
171
171
## Stack configuration for scripts
172
172
173
- With the ` stack script ` command, all Stack YAML configuration files are ignored.
173
+ With the ` stack script ` command, all Stack YAML configuration files (global and
174
+ project-level) are ignored.
174
175
175
176
With the ` stack runghc ` command, if the current working directory is inside a
176
177
project then that project's Stack project-level YAML configuration is effective
@@ -190,7 +191,7 @@ which makes use of the joke package
190
191
191
192
~~~ haskell
192
193
{- stack script
193
- --resolver lts-19.28
194
+ --resolver lts-20.4
194
195
--package acme-missiles
195
196
-}
196
197
import Acme.Missiles (launchMissiles )
@@ -201,16 +202,17 @@ main = launchMissiles
201
202
202
203
The command ` stack --script-no-run-compile Script.hs ` then behaves as if the
203
204
command
204
- ` stack script --resolver lts-19.28 --package acme-missiles --no-run --compile -- Script.hs `
205
+ ` stack script --resolver lts-20.4 --package acme-missiles --no-run --compile -- Script.hs `
205
206
had been given. ` Script.hs ` is compiled (without optimisation) and the resulting
206
207
executable is not run: no missiles are launched in the process!
207
208
208
209
## Writing independent and reliable scripts
209
210
210
211
The ` stack script ` command will automatically:
211
212
212
- * Install GHC and libraries if missing
213
- * Require that all packages used be explicitly stated on the command line
213
+ * Install GHC and libraries, if missing. ` stack script ` behaves as if the
214
+ ` --install-ghc ` flag had been passed at the command line.
215
+ * Require that all packages used be explicitly stated on the command line.
214
216
215
217
This ensures that your scripts are _ independent_ of any prior deployment
216
218
specific configuration, and are _ reliable_ by using exactly the same version of
@@ -237,7 +239,7 @@ example with `runghc`:
237
239
{- stack
238
240
runghc
239
241
--install-ghc
240
- --resolver lts-19.17
242
+ --resolver lts-20.4
241
243
--package base
242
244
--package turtle
243
245
--
@@ -260,7 +262,7 @@ it. Here is an example:
260
262
{- stack
261
263
exec ghci
262
264
--install-ghc
263
- --resolver lts-19.28
265
+ --resolver lts-20.4
264
266
--package turtle
265
267
-}
266
268
~~~
0 commit comments