haroldcarr / haskell-inline-js-example

example of how to use inline-js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use inline-js in a Haskell package.

I will start by saying, there are many things “wrong” with how this is done. But it is the first thing I have got to work. I am hoping others will suggest improvements.

usage

nix usage

assumes:

nix --version
# => nix (Nix) 2.6.1  (it might work with older versions)

cat ~/.config/nix/nix.conf
# =>
# ...
# experimental-features       = nix-command
# extra-experimental-features = flakes
# ...

nix profile install nixpkgs#haskell.packages.ghc8107.hpack

usage:

hpack && nix build

./result/bin/main
# => "  foo"

nix flake check
# => no output, unless it fails

stack usage

assumes

nix profile install nixpkgs#nodejs

usage

hpack && stack build

stack exec main
# => "  foo"

stack test
# => ...
# inline-js-example
#   left-pad: OK (0.09s)
# All 1 tests passed (0.20s)
# ...

cabal (with nix) usage.

This did not work. It was complaining about “unknown package inline-js”.

So I did the stack steps. After doing the stack steps this now works. I assume it is because I copied src/Language/* and jsbits/main.js into the project.

hpack && nix develop

cabal build

cabal run main
# => "  foo"

cabal test
# => 1 of 1 test suites (1 of 1 test cases) passed.

exit

clean

rm -rf .stack-work  dist-newstyle result

hacks to get it to compile

These steps do not need to be done again.

# I did these steps because neither stack nor cabal could find 'inline-js'.

pushd /tmp
git clone git@github.com:tweag/inline-js.git
popd

cp -rp /tmp/inline-js/inline-js/src/Language   src
cp     /tmp/inline-js/inline-js/jsbits/main.js jsbits

redundancies (but currently necessary)

inline-js is not available in nixpkgs. The flakes.nix file contains and override to install it from github. The override is from the README in Tweag’s inline-js repo. It seems the inline-js-src should really be something in the inputs section, but I do not have enough experience (yet) with nix and flakes to do that.

The inline-js repo, tag and subdir is specified in multiple places:

  • flake.nix
  • cabal.project
  • stack.yaml

They need to be kept in sync when doing updates. And, importantly the git cloning and copying of src/Language/* needs to be kept in sync. Of course, it would be best if that info was specified once and that the copying was not necessary.

needs more usage/testing

I just barely got this to work. I still don’t know how to really use inline-js. So there could be other problems that have not been flushed out.

About

example of how to use inline-js

License:Creative Commons Zero v1.0 Universal


Languages

Language:Haskell 75.1%Language:Nix 24.9%