Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

require-haskell

1.0.2 • Public • Published

Require-Haskell Build Status

require-haskell lets you require your haskell modules as asynchronous Javascript functions.

Example

var requireH = require('require-haskell');

// You can now require haskell files with requireH just like you require javascript files using require.
var haskellFunction = requireH('/path/to/a/haskell/file.hs');

// Now you can call this function from your javascript code
haskellFunction('arguments', 'go', 'here', function(err, result){
  // Now do something in the callback
});

Passing and Returning Data

The Javascript function representing the your Haskell module takes any number of arguments, and then a callback argument as it's last argument. Passing a callback is mandatory.

In the Haskell file, you can get the arguments passed in through the getArgs function from System.Environment. When your Haskell code is done executing, your callback that you passed gets called, with error and result arguments represening any errors thrown by the Haskell program or anything the program wrote to stderr in the error argument, and anything the program wrote to standard output as the result value.

Environment Variables

If you want to call the Haskell module with certain environment variables set, you can pass a second argument when requiring your Haskell module. This argument should be an object containing any environment variables you want to set or overwrite.

Example

var requireH = require('require-haskell');
var haskellFunctionWithEnvVariable = requireH('/some/file.hs', { VARNAME: 'foo' });
// Now when you call the function, the Haskell module will be run in a context that includes this new environment variable in addition to the ones it inherits from the Node proccess.

Dependencies

In order to use this module, you need to have runhaskell installed on your system. If you've installed ghc you've probably got it. Otherwise, you'll need to install it before you use require-haskell.

Intended Use

require-haskell dynamicly runs your Haskell code using runhaskell. As such, it's not going to be as perfomant as if you compile the Haskell code up front and manually spawn a subproccess to run your compiled executable. require-haskell is not intended for applications which need to do heavy lifting in Haskell, or ones which need to call the imported Haskell function many times per second.

What it is good for is scripting, EDSLs, or configuration files writted in Haskell. It's quite likely you'll be able to find even more uses for it.

Testing

To run the tests for require-haskell, make sure you've installed jasmine, and run npm test.

Contributing

Pull requests are welcome. If you've got an idea of how to improve require-haskell go right ahead!

install

npm i require-haskell

Downloadsweekly downloads

3

version

1.0.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability