So I noticed, while answering this question, that the one who asked the question appears to be a javascript developer. And as the code I wrote in haskell is easy enough, I thought I give haste a try and try to compile it to javascript.
So, I downloaded the Windows binary package of haste (why does the .msi require a reboot?!!?), added it to my path, issued haste-cabal update and haste-cabal install split and after a bit of reading the output of hastec --help, I issued:
PS E:\h\stackoverflow> hastec -o hexagon.js --pretty-print hexagon.hs
as my best guess on how to get the output I am looking for.
Opposite to my expectation, haste output was this:
hastec.exe: user error (shell expression failed in readModule: Data.Binary.Get.runGet at position 8: not enough bytes)
So, my question: What do I have to do to get a java script source file?
Is it possible that you have an old version of Haste lying around, or have intermediate files (
.jsmod, for instance) from a different version of the compiler in your source directory? This sounds like the (quite unhelpful) error message Haste produces when it runs into a corrupted intermediate file.Check that the version of the binary you're calling is what you expect (
hastec --version). Then, try getting rid of all intermediate files in the directory as well as any files in%USERPROFILE%\AppData\Roaming\haste, reinstallingsplit, and recompiling with the-fforce-recompflag. You should also add amainfunction, so that Haste has an entry point to your program from which to start linking. If all you want to do is to make some Haskell function available to external JavaScript, you can use theexportforeign function interface:You will probably also want to compile your program with the
--onexecflag, to make sure thatmainruns and exportspictureimmediately when loaded, and not on page load which is the default:After doing this, any code included after
hexagon.jswill be able to call e.g.Haste.picture(5);in order to produce a picture of size 5.(Re: MSI installer requiring a reboot, this is required since it adds the Haste binaries to your
%PATH%, which does not take effect immediately. I assume that a re-login would be enough to make it take effect, however.)