secrettore.blogg.se

Haskell code
Haskell code






haskell code
  1. #Haskell code install#
  2. #Haskell code code#

-install-ghc is the flag to install ghc, if it is not already available.Settings = setPort port $ setBeforeMainLoop (putStrLn msg) defaultSettings The resolver argument is mandatory, and Stack will compile and run the simple.hs file immediately after invocation using the lts-14.18 Stackage snapshot.Īlternatively, we can put all of the configuration information into the script itself, like this: " To run this with the stack script interpreter, we can do the following: $ stack script simple.hs -resolver lts-14.18

#Haskell code code#

Here’s the source code we want to run, in a filed called simple.hs: main :: IO ()

haskell code

An example of stack as a bash replacementįor our first example, we’ll use stack to run a single file of Haskell source code as a script.A simple Servant server that statically serves your current working directory.A basic example of the Scripting Interpreter.This article contains the following examples of using scripting with stack: Note: When running a stack script inside of a stack project, it’s important to consider that stack will read settings from your project.yaml and stack.yaml, which may cause issues.

haskell code

Therefore, for the sake of simplicity, we’ll assume that these scripts are run outside of a stack project, and stack is invoked in the same directory as the script file. Stack is a build tool primarily designed for reproducible builds, done by specifying a resolver in a configuration file, usually your projects stack.yaml and package.yaml With Stack’s scripting feature, we still get reproducible builds by specifying a resolver, but move this specification to the file we are compiling, or as a command line argument. This use case pairs well with the Turtle library, although this approach does have downsides. Using Haskell as a scripting language, or replacement for Shell/Bash/Zsh. Personally, I find this helpful when exploring new libraries or writing small programs. Lower the configuration barrier: write an independently compiling Haskell source code file with package dependencies without having to configure a new stack or cabal project. There are at least two additional motivations, besides reproducible builds, that you might want to use Stack’s scripting feature: If you share small, single module, self contained haskell examples, stack script gives us an easy way to get reproducible builds, by pinning the dependencies to a Stackage snapshot within a comment at the top of your Haskell code.








Haskell code