Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

require-haskell

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-haskell

Require haskell functions from node

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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!

Keywords

FAQs

Package last updated on 29 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc