npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

require-haskell

v1.0.2

Published

Require haskell functions from node

Downloads

3

Readme

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!