1
+2
+3
+4
+5
+6
+7
+8
+9
with (import <nixpkgs> {});
+let
+ customGhc = haskellPackages.ghcWithPackages (pkgs: with pkgs; [ containers ]);
+in
+mkShell {
+ buildInputs = [
+ customGhc
+ ];
+}
+
+diff --git a/index.html b/index.html index 2be7afd..aa79ceb 100644 --- a/index.html +++ b/index.html @@ -94,7 +94,7 @@ pre.pygments .tok-il { color: #666666 } /* Literal.Number.Integer.Long */
.cabal file required).cabal file required)Occasionally you might want to run a short Haskell program that depends on a Haskell library,
+but you don’t want to bother writing a cabal file.
+This shell provides access to the Haskell containers library (package).
1
+2
+3
+4
+5
+6
+7
+8
+9
with (import <nixpkgs> {});
+let
+ customGhc = haskellPackages.ghcWithPackages (pkgs: with pkgs; [ containers ]);
+in
+mkShell {
+ buildInputs = [
+ customGhc
+ ];
+}
+
+Here’s a short Haskell program that uses it.
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
import Data.Map
+
+m :: Map String Int
+m = fromList [("cats", 3), ("dogs", 2)]
+
+main :: IO ()
+main = do
+ let cats = findWithDefault 0 "cats" m
+ let dogs = findWithDefault 0 "dogs" m
+ let zebras = findWithDefault 0 "zebras" m
+ print $ "I have " ++ show cats ++ " cats, " ++ show dogs ++ " dogs, and " ++ show zebras ++ " zebras."
+
+Here’s a demonstration using the program.
+$ nix-shell +$ runghc Main.hs +"I have 3 cats, 2 dogs, and 0 zebras."+
This shell has the environment variable FOO set to “bar”
flake.nix.
The script should start with two “shebang” (#!) commands. The first
-should invoke nix-shell. The second should declares the scrpt
+should invoke nix-shell. The second should declares the script
interpreter and any dependencies. Here are some examples.
1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
#! /usr/bin/env nix-shell
+#! nix-shell -p "haskellPackages.ghcWithPackages (p: [p.containers])"
+#! nix-shell -i runghc
+
+import Data.Map
+
+m :: Map String Int
+m = fromList [("cats", 3), ("dogs", 2)]
+
+main :: IO ()
+main = do
+ let cats = findWithDefault 0 "cats" m
+ let dogs = findWithDefault 0 "dogs" m
+ let zebras = findWithDefault 0 "zebras" m
+ print $ "I have " ++ show cats ++ " cats, " ++ show dogs ++ " dogs, and " ++ show zebras ++ " zebras."
+
+"I have 3 cats, 2 dogs, and 0 zebras."+