nix-eval: Evaluate Haskell expressions using Nix to get packages

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Evaluate Haskell expressions using Nix to get packages


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.3.3.0, 0.3.3.0, 0.4.1.0
Change log None available
Dependencies base (>=4.8 && <4.10), hindent (>=4.0), process, strict [details]
License LicenseRef-GPL
Author Chris Warburton
Maintainer chriswarbo@gmail.com
Category Language
Home page http://chriswarbo.net/git/nix-eval
Source repo head: git clone http://chriswarbo.net/git/nix-eval.git
Uploaded by chriswarbo at 2016-11-12T15:57:39Z

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for nix-eval-0.3.3.0

[back to package description]

Dependency-Injecting Eval for Haskell

This Haskell package is a crude implementation of eval, as found in dynamic languages like Lisp, Python, Javascript, etc. It lets us construct Haskell code programatically (either at run time, or in Template Haskell), and attempt to evaluate it.

What sets this package apart from other eval implementations, is the ability to control which packages and modules are available during evaluation. This is achieved by calling out to the Nix package manager.

Implementation Details

Expr is the type of expressions, which contains a list of package names, a list of modules to import, a list of compiler flags, a list of Strings to put in the generated module and a String of Haskell code to evaluate. All of these are just Strings internally, but we use wrappers to prevent accidentally using packages as modules, etc.

A few combinators are provided for common manipulations, for example qualified "Foo" "bar" will produce the expression "Foo.bar" with "Foo" in its module list. The OverloadedStrings extension allows packages, modules, flags and expressions to be written as literals. Note that literal expressions are given an empty context; you will have to specify any required modules, packages, etc. separately.

When evaluated, the Haskell code is prefixed by an import of each module, the "preamble" strings (if any) and wrapped in main = putStr (..). This code is piped into runhaskell. If any flags are specified, they are appended as arguments to the runhaskell command.

The runhaskell process itself is invoked via the nix-shell command, which provides all of the required packages via the ghcWithPackages mechanism of nixpkgs. Packages are taken from nixpkgs's haskellPackages set by default, which can be overridden by setting the NIX_EVAL_HASKELL_PKGS environment variable to the path of a Nix file. Note that the package names used in your Haskell code should correspond to the keys in this package set, which might differ from those used on Hackage.

If the process exits successfully, its stdout will be returned wrapped in Just; otherwise Nothing is returned. If you wish to alter the main implementation, use Language.Eval.Internal.eval'

This implementation is a little rough; for example, you may prefer to use Text rather than String; use a better representation like the syntax trees from TemplateHaskell or haskell-src-exts instead; or accumulate packages and modules monadically.

The intention of this library is to provide a simple, minimal base to support such design choices, and String is the lowest common denominator. You're welcome, and encouraged, to build more sophisticated APIs; as long as you can pretty-print to a String, they should work out of the box.

This is also why we return the contents of stdout, rather than trying to parse it into a more appropriate type: it's not our place to choose how the result should be parsed, so we avoid the problem; by that point, our job is done.

Limitations