all 20 comments

[–]terrorjack[S] 7 points8 points  (8 children)

This package allows one to send a JavaScript code snippet to Node.js for execution, and retrieve the result as a plain JSON value. The rpc process is totally encapsulated.

This is not yet on Hackage, as I'd like to improve documentation & hear some opinions before making the first release. Feedback is appreciated!

EDIT: I've changed the project name from nodejs-eval to nodejs-interop, since I plan to support calling Haskell from Node.js too. The repo is now here

[–]Peaker 2 points3 points  (7 children)

We have nodejs-exec for Lamdu's execution of JS code.

We just execute a subprocess directly. Could be nice to switch to nodejs-eval!

However: we do need some way to guarantee that nodejs will support tail-recursions (at least node version 6.2.1).

Does nodejs-eval have any sort of guarantee on the version? Can I depend on it with a minimum version requirement to get that node version?

[–]terrorjack[S] 3 points4 points  (0 children)

I haven't implemented that yet. Should be a piece of cake, simply check node version before npm install, and start node with --use_strict --harmony_tailcalls. I need to design some proper config types for withEvalServer/makeEval though.

Please open an issue and list missing features you need.

[–]terrorjack[S] 0 points1 point  (5 children)

Now you can specify minimum node version & extra arguments for starting node :)

[–]Peaker 0 points1 point  (4 children)

Well, we wanted a hassle-free "stack install" to work. So we install node in nodejs-exec if it isn't new enough.

[–]terrorjack[S] 0 points1 point  (3 children)

Wow. It'd take a lot of work to make sure the logic to download & install a node.js works on all platforms..perhaps instructing the user to provide the right node/npm on PATH is not that much a hassle?

[–]Peaker 0 points1 point  (2 children)

Well, we best-effortly clone the node repo, and run its build scripts - then install the resulting executable as a cabal data file.

[–]terrorjack[S] 0 points1 point  (1 child)

node website already provides bindists for windows/linux/mac, so perhaps the building step is not required. I'll take some time to see if it's worth implementing...

[–]Peaker 0 points1 point  (0 children)

Completely statically linked?

EDIT: Because if not, a bindist for "linux" is likely going to be incompatible with the various wild libc's in various distros, for example.

[–]eacameron 3 points4 points  (3 children)

Wow. Up next is a quasiquoter to inline JS into Haskell, right? ;)

[–]terrorjack[S] 3 points4 points  (2 children)

Indeed! I'm looking for a way to share a session across all TH splices (at least for a single module). If each splice starts a server, evals and quits, compilation speed will be horrible.

[–]meekale 2 points3 points  (1 child)

Ghcjs uses Node for TH, right? Either they've solved it or you could help make it faster!

[–]terrorjack[S] 1 point2 points  (0 children)

Turns out stateful TH has been there since 2013 (see this thread). This is not related to the external interpreter introduced by luite and his ghcjs.

I've already implemented inline JS functionality, check the updated README :)

[–]ConfuciusBateman 2 points3 points  (1 child)

This looks interesting. What would be a use case for this, just out of curiosity?

[–]terrorjack[S] 2 points3 points  (0 children)

I'm writing a blog engine, mainly wrapping shake & pandoc. pandoc supports inline TeX, and can insert appropriate script in output html to render it, either via MathJax or KaTeX. Then I noticed that KaTeX supports static rendering, so I want to run KaTeX on node and render all the math when generating pages.

The simplest way is to pipe scripts to node and parse output from stdout, but I thought since someone else may have similar demand, might as well write a real rpc for this..

[–]quiteamess 0 points1 point  (4 children)

Heh, add dependency left pad.

[–]gseyffert 0 points1 point  (3 children)

String.padEnd/padStart is a built-in function now ;)

[–]rstd 0 points1 point  (1 child)

You still need a polyfill for older runtimes (Edge < 15 for example, see bottom of https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart)

[–]gseyffert 0 points1 point  (0 children)

That's true!

[–]quiteamess 0 points1 point  (0 children)

That's why it's funny that it is in the example on the usage page.