2 ms·
You can always defunctionalise some particular code, to get a more static/declarative DSL. That's already quite a common pattern in Nix, where we can write Nix
by chriswarbo 3y ago
You can always defunctionalise some particular code, to get a more static/declarative DSL. That's already quite a common pattern in Nix, where we can write Nix functions that act as interpreters for some more "declarative" DSL; indeed, many of the "foo2nix" utilities are just interpreters, written in Nix, for some third-party DSL; e.g. the "callCabal2nix" function in Nixpkgs can read the .cabal file of a Haskell project, and there are many other examples. The `builtins.readJSON` function is a particularly useful building block for such functions.
I don't think it's a good idea to defunctionalise the Nix language itself, since the result would either be too inflexibile or incredibly complex. Keep in mind that the Nix language has no idea what a shell is, or any concept of "package", etc. yet it's flexible enough to write functions like `runCommand`, which is used in the example above.
Also, it's reasonable to argue that Nix is already declarative, since that's what the `.drv` files are for! However, they're so tedious to work with that it's preferable to generate them using a "proper" language like the Nix expression language (or Guile Scheme if you're using Guix)!
(See http://www.chriswarbo.net/projects/nixos/bottom_up.html http://www.chriswarbo.net/projects/nixos/bottom_up.html for a more in-depth explanation of .drv files, and how they relate to the Nix expression language)