diff --git a/shell.nix b/shell.nix index dcf87db..0eab84d 100644 --- a/shell.nix +++ b/shell.nix @@ -1,5 +1,5 @@ # { pkgs ? import {} }: -{ pkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs/archive/19.09-beta.tar.gz) {} }: +{ pkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs/archive/19.09.tar.gz) {} }: pkgs.mkShell { buildInputs = [ pkgs.coreutils pkgs.html-xml-utils diff --git a/src/posts/0010-Haskell-Now/hello.hs b/src/posts/0010-Haskell-Now/hello.hs new file mode 100755 index 0000000..cfed90d --- /dev/null +++ b/src/posts/0010-Haskell-Now/hello.hs @@ -0,0 +1,5 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i runghc +#! nix-shell -p "ghc.withPackages (ps: [ ps.protolude ])" +#! nix-shell -I nixpkgs="https://github.com/NixOS/nixpkgs/archive/19.09.tar.gz" +main = putStrLn "Hello World!" diff --git a/src/posts/0010-Haskell-Now/index.org b/src/posts/0010-Haskell-Now/index.org index 32fc54a..fdf9cb2 100644 --- a/src/posts/0010-Haskell-Now/index.org +++ b/src/posts/0010-Haskell-Now/index.org @@ -185,6 +185,46 @@ The environment in which you will learn Haskell will be quite different from an environment to use Haskell seriously for a new project. This is because, there are too much choices for that. + +Mainly, you can start by writing your code in a file and executing it by +putting one of the following at the top of your file: + +If you chose Nix: https://nixos.org/nix/ + +#+BEGIN_EXAMPLE +#! /usr/bin/env nix-shell +#! nix-shell -i runghc +#! nix-shell -p "ghc.withPackages (ps: [ ps.protolude ])" +#! nix-shell -I nixpkgs="https://github.com/NixOS/nixpkgs/archive/19.09.tar.gz" +#+END_EXAMPLE + + +If you chose Stack: https://haskellstack.org + +#+BEGIN_EXAMPLE haskell +#!/usr/bin/env stack +{- stack script + --resolver lts-14.16 + --install-ghc + --package protolude +-} +#+END_EXAMPLE + +*** code :noexport: +:PROPERTIES: +:CUSTOM_ID: code +:END: + + +#+name nixb +#+begin_src elisp :export none +(defun nixb () + "#! /usr/bin/env nix-shell\n#! nix-shell -i runghc\n#! nix-shell -p \"ghc.withPackages (ps: [ ps.protolude ])\"\n#! nix-shell -I nixpkgs=\"https://github.com/NixOS/nixpkgs/archive/19.09.tar.gz\"") +#+end_src + +#+RESULTS: +: nixb + ** Don't be afraid :PROPERTIES: :CUSTOM_ID: don't-be-afraid @@ -199,39 +239,29 @@ At first I won't show you any Haskell super power. I will start with similarities between Haskell and other programming languages. Let's jump to the mandatory "Hello World". -#+BEGIN_SRC haskell - main = putStrLn "Hello World!" +[[./hello.hs]] +#+NAME: hello.hs +#+BEGIN_SRC haskell :tangle hello.hs :shebang (nixb) +main = putStrLn "Hello World!" #+END_SRC -To run it, you can save this code in a =hello.hs= and: - #+BEGIN_EXAMPLE - ~ runhaskell ./hello.hs - Hello World! +> chmod +x hello.hs +> ./hello.hs +Hello World! #+END_EXAMPLE -or if you use =stack= first run =stack setup= and then: - #+BEGIN_EXAMPLE - ~ stack runhaskell ./hello.hs - Hello World! +> stack ghc -- hello.hs +> ./hello +Hello World! #+END_EXAMPLE -You could also download the literate Haskell source. You should see a -link just above the introduction title. Download this file as -=00_hello_world.lhs= and: - -#+BEGIN_EXAMPLE - ~ runhaskell 00_hello_world.lhs - Hello World! -#+END_EXAMPLE - ------ - Now, a program asking your name and replying "Hello" using the name you entered: -#+BEGIN_SRC haskell +#+NAME: name.hs +#+BEGIN_SRC haskell :tangle name.hs :shebang (nixb) main = do print "What is your name?" name <- getLine diff --git a/src/posts/0010-Haskell-Now/name.hs b/src/posts/0010-Haskell-Now/name.hs new file mode 100755 index 0000000..8a43380 --- /dev/null +++ b/src/posts/0010-Haskell-Now/name.hs @@ -0,0 +1,8 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i runghc +#! nix-shell -p "ghc.withPackages (ps: [ ps.protolude ])" +#! nix-shell -I nixpkgs="https://github.com/NixOS/nixpkgs/archive/19.09.tar.gz" +main = do + print "What is your name?" + name <- getLine + print ("Hello " ++ name ++ "!") diff --git a/src/posts/rss-gen.org b/src/posts/rss-gen.org index 482538d..aa36886 100644 --- a/src/posts/rss-gen.org +++ b/src/posts/rss-gen.org @@ -225,7 +225,7 @@ Along my script I have a [[file:rss-gen/shell.nix][=shell.nix=]] file containing #+begin_src nix # { pkgs ? import {} }: -{ pkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs/archive/19.09-beta.tar.gz) {} }: +{ pkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs/archive/19.09.tar.gz) {} }: pkgs.mkShell { buildInputs = [ pkgs.coreutils pkgs.html-xml-utils pkgs.zsh pkgs.perl pkgs.perlPackages.URI ]; } diff --git a/src/posts/rss-gen/shell.nix b/src/posts/rss-gen/shell.nix index 67e388e..468a2a8 100644 --- a/src/posts/rss-gen/shell.nix +++ b/src/posts/rss-gen/shell.nix @@ -1,5 +1,5 @@ # { pkgs ? import {} }: -{ pkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs/archive/19.09-beta.tar.gz) {} }: +{ pkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs/archive/19.09.tar.gz) {} }: pkgs.mkShell { buildInputs = [ pkgs.coreutils pkgs.html-xml-utils pkgs.zsh ]; } diff --git a/src/slides/Intro-to-FP-with-Haskell.org b/src/slides/Intro-to-FP-with-Haskell.org index 9a586a7..e346af1 100644 --- a/src/slides/Intro-to-FP-with-Haskell.org +++ b/src/slides/Intro-to-FP-with-Haskell.org @@ -196,7 +196,7 @@ Avec Nix: https://nixos.org/nix/ #! /usr/bin/env nix-shell #! nix-shell -i runghc #! nix-shell -p "ghc.withPackages (ps: [ ps.protolude ])" -#! nix-shell -I nixpkgs="https://github.com/NixOS/nixpkgs/archive/18.09-beta.tar.gz" +#! nix-shell -I nixpkgs="https://github.com/NixOS/nixpkgs/archive/18.09.tar.gz" #+END_SRC *** Hello World! (1/3)