Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help on start using purescript on NixOS

I am trying to setup hello world project with purescript on NixOs and have couple questions,

  1. Official purescript website recommend installation via npm but there is no nixos.nodePackages.purescript, instead there are at least 2 variants I found in nixpkgs
    • nixos.purescript
    • nixos.haskellPackages.purescript

What are the different?

  1. Official site recommend pulp and bower via npm but only nodePackages.bower is avaliable and there is undocumented psc-package.

What should be the nix way to handle purescript packages?

  1. The sample code on official site (see hello.purs bellow) doesn't even compile,

with these error.

$ purs compile hello.purs

Error found:
at hello.purs line 1, column 1 - line 1, column 1

Unable to parse module:
unexpected "import"
expecting "module"

I add module Hello to code but still failed.

$ purs compile hello.purs 
Error 1 of 2:

  in module Hello
  at hello.purs line 2, column 1 - line 2, column 15

    Module Prelude was not found.
    Make sure the source file exists, and that it has been provided as an input to psc.


  See https://github.com/purescript/documentation/blob/master/errors/ModuleNotFound.md for more information,
  or to contribute content related to this error.

Error 2 of 2:

  in module Hello
  at hello.purs line 3, column 1 - line 3, column 39

    Module Control.Monad.Eff.Console was not found.
    Make sure the source file exists, and that it has been provided as an input to psc.


  See https://github.com/purescript/documentation/blob/master/errors/ModuleNotFound.md for more information,
  or to contribute content related to this error.

How the correct workflow should be?


The goal is to have minimal example project with a single hello.purs running in web browser.

This is hello.purs

module Hello where
import Prelude
import Control.Monad.Eff.Console (log)

greet :: String -> String
greet name = "Hello, " <> name <> "!"

main = log (greet "World")

It would be really helpful if you can also provide shell.nix for nix-shell or default.nix for nix-build.

Found this 2 years old guild, I am trying it but I still not have answer to all of my questions.

like image 200
wizzup Avatar asked Sep 07 '17 10:09

wizzup


1 Answers

  1. nixos.purescript is just the static executables for nixos.haskellPackages.purescript; this skips building/installing PureScript as a Haskell library
  2. You can install Pulp via npm install pulp - the binary will be installed to node_modules/.bin/pulp
  3. The sample code doesn't compile because you haven't downloaded the dependencies via Bower. You can install them via bower install purescript-prelude purescript-console.

But node_modules/.bin/pulp init will give you a Bower file and you can run bower install to give you a basic project. You can then do node_modules/.bin/pulp run to execute it using node.js, but you'll probably want pulp browserify --to example.js to get a file you can put in a <script> tag in HTML.

like image 197
Brian McKenna Avatar answered Oct 25 '22 17:10

Brian McKenna