Skip to content

Instantly share code, notes, and snippets.

@heath
Forked from monadplus/running-haskell-scripts.md
Last active May 26, 2020 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heath/5df7b0df76bad1f0f61e4a15d6456808 to your computer and use it in GitHub Desktop.
Save heath/5df7b0df76bad1f0f61e4a15d6456808 to your computer and use it in GitHub Desktop.
Running a haskell script without GHC using nix
#!/usr/bin/env nix-shell
#nix-shell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [ mwc-random ])" -i runghc

{-# LANGUAGE ScopedTypeVariables #-}

import System.Random.MWC
import Data.Vector.Unboxed
import Control.Monad.ST

main = do
  vs <- withSystemRandom $
        \(gen::GenST s) -> uniformVector gen 20 :: ST s (Vector Int)
  print vs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment