Given the following haskell script
generate-random-samples.hs that requires mwc-random
… how do you run it without having to globally install the package or having to build a whole cabal project ?
One of the simplest approaches using nix is the following:
In order to reuse the command so other people can run the script, you can add the following
So now you only need to call
$ nix-shell to enter into a pure shell with a specific GHC version that includes all your dependencies:
Improving the first approach
The only issue is that you must be aware of how nix work in order to be able to run the script.
But these could be solved using bash shebangs in your haskell script:
So now, you can run your haskell script in an environment without ghc:
After reading the following comment in reddit, I think it is worth mentioning that you can achieve better modularity in exchange of maintainability, by having everything on the haskell script, without having to depend on a