Need help on start using purescript on NixOS - purescript

I am trying to setup hello world project with purescript on NixOs and have couple questions,
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?
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?
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.

nixos.purescript is just the static executables for nixos.haskellPackages.purescript; this skips building/installing PureScript as a Haskell library
You can install Pulp via npm install pulp - the binary will be installed to node_modules/.bin/pulp
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.

Related

Why can't I add a package (module) I created in Julia?

I am having trouble installing a module I created in Julia. I am running the Julia plugin under Visual Studio Code. If I run the file below with Ctrl+F5 I get a message
ERROR: LoadError: ArgumentError: Package Utils not found in current path:
- Run `import Pkg; Pkg.add("Utils")` to install the Utils package.
This is the file:
module demo
using Utils
greet() = print("Hello World!")
end # module
If I follow the advice on the error message I get another error message:
ERROR: LoadError: The following package names could not be resolved:
* Utils (not found in project, manifest or registry)
I also tried inserting this line:
import Pkg; Pkg.add(path="C:/Dropbox/Code/Julia/demo/src/Utils.jl")
and got this message (although the path definitely exists):
ERROR: LoadError: Path `C:/Dropbox/Code/Julia/demo/src/Utils.jl` does not exist.
The files demo.jl and Utils.jl are in C:\Dropbox\Code\Julia\demo\src\ and the demo project has been activated as can be seen in the REPL. The OS is Windows 10 Pro.
Any help will be greatly appreciated. Lots of time wasted trying to make this work.
Module and packages are not the same things. In short, packages are modules plus a set of metadata that make it easy for the package to be found and interact well with other packages. See here for a tutorial to write Julia packages:
https://syl1.gitbook.io/julia-language-a-concise-tutorial/language-core/11-developing-julia-packages
In your case, if you want to load a local module, just type include("fileWhereThereIsTheModule.jl") followed by a using Main.MyModule or using .MyModule. Note the dot... without it, Julia would indeed look for a package and to let it find your Demo or Util module you would have to either change an environmental variable or place your module file in certain predefined folders. Using include followed by the "absolute or relative position" of the module you don't have to do either.

Purescript 0.12 Getting Started

i`m trying to run the very basic flow:
1) install tools:
npm install -g pulp bower
Pulp version 12.2.0
purs version 0.12.0 using C:\Users\panda.psvm\current\bin\purs.EXE
C:\Users\panda>bower --version
1.8.4
2) following steps from this answer i installed purs https://stackoverflow.com/a/50554135/1358421
C:\Users\panda>purs --version
0.12.0
Ok, lets create a project.
c:\home\projects\sandbox\purr>mkdir hello-purr
c:\home\projects\sandbox\purr>cd hello-purr
c:\home\projects\sandbox\purr\hello-purr>
pulp init
c:\home\projects\sandbox\purr\hello-purr>pulp init
* Generating project skeleton in c:\home\projects\sandbox\purr\hello-purr
bower purescript-console#* cached https://github.com/purescript/purescript-console.git#4.1.0
bower purescript-console#* validate 4.1.0 against https://github.com/purescript/purescript-console.git#*
bower purescript-prelude#* cached https://github.com/purescript/purescript-prelude.git#4.0.0
bower purescript-prelude#* validate 4.0.0 against https://github.com/purescript/purescript-prelude.git#*
bower purescript-prelude#^4.0.0 cached https://github.com/purescript/purescript-prelude.git#4.0.0
bower purescript-prelude#^4.0.0 validate 4.0.0 against https://github.com/purescript/purescript-prelude.git#^4.0.0
bower purescript-effect#^2.0.0 cached https://github.com/purescript/purescript-effect.git#2.0.0
bower purescript-effect#^2.0.0 validate 2.0.0 against https://github.com/purescript/purescript-effect.git#^2.0.0
bower purescript-console#^4.1.0 install purescript-console#4.1.0
bower purescript-prelude#^4.0.0 install purescript-prelude#4.0.0
bower purescript-effect#^2.0.0 install purescript-effect#2.0.0
purescript-console#4.1.0 bower_components\purescript-console
├── purescript-effect#2.0.0
└── purescript-prelude#4.0.0
purescript-prelude#4.0.0 bower_components\purescript-prelude
purescript-effect#2.0.0 bower_components\purescript-effect
└── purescript-prelude#4.0.0
bower purescript-psci-support#* cached https://github.com/purescript/purescript-psci-support.git#4.0.0
bower purescript-psci-support#* validate 4.0.0 against https://github.com/purescript/purescript-psci-support.git#*
bower purescript-psci-support#^4.0.0 install purescript-psci-support#4.0.0
purescript-psci-support#4.0.0 bower_components\purescript-psci-support
├── purescript-console#4.1.0
├── purescript-effect#2.0.0
└── purescript-prelude#4.0.0
Skeleton of project successfully generated.
Trying to run it:
pulp run
* Building project in c:\home\projects\sandbox\purr\hello-purr
Error 1 of 2:
in module Main
at src\Main.purs line 4, column 1 - line 4, column 31
Module Control.Monad.Eff was not found.
Make sure the source file exists, and that it has been provided as an input to the compiler.
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 Main
at src\Main.purs line 5, column 1 - line 5, column 48
Module Control.Monad.Eff.Console was not found.
Make sure the source file exists, and that it has been provided as an input to the compiler.
See https://github.com/purescript/documentation/blob/master/errors/ModuleNotFound.md for more information,
or to contribute content related to this error.
* ERROR: Subcommand terminated with exit code 1
No luck :(
pulp test
pulp build
The same errors - It can`t find modules.
Did i miss something? Please, advice.
Thanks
Purescript 0.12 pulls in newer versions of the Effect and Console libraries, unfortunately pulp init has not yet been updated to correct the generated example to match (see https://github.com/purescript-contrib/pulp/issues/337)
just update the code in Main.purs to:
module Main where
import Prelude (Unit)
import Effect
import Effect.Console (log)
main :: Effect Unit
main = do
log "Hello sailor!"`
to get started.
Found solution.
don't need bower at all
instead, there is a psc-package (another package manager)
it didn't installed correctly on my Windows 10 with npm install -g psc-package
there was no psc-package.exe file in directory ${username}\AppData\Roaming\npm\node_modules\psc-package\vendor
So, you need to fix install.js file and replace
ignore: ['psc-package']
with
ignore: [bin.use()]
then run fixed installation with
${username}\AppData\Roaming\npm\node_modules\psc-package\lib> node install
after that, In the vendor folder you may find psc-package.exe
Then, i followed this tutorial:
https://github.com/justinwoo/purescript-0.12.0-hello-world
and
Build successful.
look, show on Record:
{ apple: "banana" }

Error installing purescript-list

I'm new to Purescript and am following the tutorial for installation. Purescript itself is working and I can start the CLI using pulp psci, but installing purescript-list runs into trouble.
Having entered the command bower install purescript-lists --save, I get a long list of package names, but when it gets to purescript-eff and purescript-prelude I run into some version conflicts:
bower purescript-eff#^2.0.0 cached https://github.com/purescript/purescript-eff.git#2.0.0
bower purescript-eff#^2.0.0 validate 2.0.0 against https://github.com/purescript/purescript-eff.git#^2.0.0
Unable to find a suitable version for purescript-eff, please choose one by typing one of the numbers below:
1) purescript-eff#^1.0.0 which resolved to 1.0.0 and is required by purescript-console#1.0.0
2) purescript-eff#^2.0.0 which resolved to 2.0.0 and is required by purescript-st#2.0.0
Prefix the choice with ! to persist it to bower.json
? Answer
A similar message is shown for purescript-prelude. No matter which options I choose, both pulp build and pulp run fail with:
$ pulp build
* Building project in /Developer/purescript/training1
Error found:
in module PSCI.Support
at /Developer/purescript/training1/bower_components/purescript-psci-support/src/PSCI/Support.purs line 10, column 34 - line 10, column 53
Cannot import value unsafeInterleaveEff from module Control.Monad.Eff.Unsafe
It either does not exist or the module does not export it.
See https://github.com/purescript/purescript/wiki/Error-Code-UnknownImport for more information,
or to contribute content related to this error.
Compiling PSCI.Support
* ERROR: Subcommand terminated with exit code 1
What have I missed here?
Thanks
Chris W
If you are using psc version 0.10.* you should go with prelude, lists and eff v2*.
If you are using psc version 0.9.* you should go with prelude, lists and eff v1*.
If you are using psc 0.10.* you might want to update pulp to version 9.1.0
The problem occurs due to breaking changes between psc 0.9 and 0.10 and the relevant libraries. by writing bower install purescript-lists --save you are asking bower for the latest dependencies which conflict with the dependency versions specified in your bower.json.

coq Hello World example (with opam) can't find libraries

I was following a coq HelloWorld tutorial (code below), and couldn't get the program to compile. I followed the installation steps and installed opam install coq:io:system. My opam installation is at the default location ~/.opam. But still, I got an error about
Toplevel input, characters 53-67:
Error: The reference System.effects was not found in the current environment.
This is with either emacs/proofgeneral or coqide (8.4pl6, ubuntu 14.04). Does any one know how to fix the issue?
Here's the code which I copied into a file called hello_world.v and loaded into emacs/coqide:
Require Import Coq.Lists.List.
Require Import Io.All.
Require Import Io.System.All.
Require Import ListString.All.
Import ListNotations.
Import C.Notations.
(** The classic Hello World program. *)
Definition hello_world (argv : list LString.t) : C.t System.effects unit :=
System.log (LString.s "Hello world!").
-- Update ---
#gtzinos, I followed the readme in https://github.com/clarus/coq-hello-world. This time there was no complaint about System.effects, but there was a new error about Extraction.launch not found. I tried:
git clone https://github.com/clarus/coq-hello-world.git
cd coq-hello-world
./configure.sh && make
and got:
"coqc" -q -R src HelloWorld src/Main
File "/.../coq-hello-world/src/Main.v", line 32, characters 19-36:
Error: The reference Extraction.launch was not found in the current
environment.
I tried also to make in the extraction folder, but without success. Any pointers?
New versions of the coq:io and coq:io:system libraries were just released. Run:
opam update
opam upgrade
to make sure you have coq:io:system in version at least 2.3.0. Now Extraction.launch should be available. System.effects has been replaced by System.effect.

Boost.Python __init__() should return None, not 'NoneType'

I have a whole bunch of working C++ code that I want to write Python bindings for. I'm trying to use Boost.Python since it seems to be the easiest way to get this working, but it isn't cooperating. Here's part of the code for the extension module I'm trying to build:
BOOST_PYTHON_MODULE(libpcap_ext) {
using namespace boost::python;
class_<PacketEngine>("PacketEngine")
.def("getAvailableDevices", &PacketEngine_getAvailableDevices);
}
Bjam seems to be a pain and refuses to recognize my Pythonpath or allow me to link with libpcap, so I'm using CMake. Here's my CMakeLists file, which can import and build everything just fine (outputs libpcap.so as expected):
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "DEBUG")
#SET(CMAKE_BUILD_TYPE "RELEASE")
#SET(CMAKE_BUILD_TYPE "RELWITHDEBINFO")
#SET(CMAKE_BUILD_TYPE "MINSIZEREL")
ENDIF()
FIND_PACKAGE(Boost 1.55.0)
find_package(PythonLibs REQUIRED)
IF(Boost_FOUND)
INCLUDE_DIRECTORIES("${Boost_INCLUDE_DIRS}" "${PYTHON_INCLUDE_DIRS}")
SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_MULTITHREADED ON)
SET(Boost_USE_STATIC_RUNTIME OFF)
FIND_PACKAGE(Boost 1.55.0 COMPONENTS python)
ADD_LIBRARY(pcap_ext MODULE PacketWarrior/pcap_ext.cc PacketWarrior/PacketEngine.h PacketWarrior/PacketEngine.cc PacketWarrior/Packet.h PacketWarrior/Packet.cc)
TARGET_LINK_LIBRARIES(pcap_ext pcap)
TARGET_LINK_LIBRARIES(pcap_ext ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
ELSEIF(NOT Boost_FOUND)
MESSAGE(FATAL_ERROR "Unable to find correct Boost version. Did you set BOOST_ROOT?")
ENDIF()
ADD_DEFINITIONS("-Wall")
And my pcap.py file that attempts to utilize the module:
import libpcap_ext
engine = libpcap_ext.PacketEngine()
print engine.getAvailableDevices()
But whenever I try to run the module, I get the following error:
Traceback (most recent call last):
File "../pcap.py", line 2, in <module>
engine = libpcap_ext.PacketEngine()
TypeError: __init__() should return None, not 'NoneType
I'm assuming it's because Boost.Python is trying to use Python 3 and my system default is Python 2.7.3. I've tried changing my user-config.jam file (in my boost_1_55_0 directory) to point to Python 2.7 and tried building:
# Configure specific Python version.
# using python : 2.7 : /usr/bin/python2.7 : /usr/include/python2.7 : /usr/lib ;
Boost.Python's installation instructions [0] seem to fail for me when I try to build quickstart with bjam (lots of warnings), so I tried following the Boost Getting Started instructions [1] to build a Python header binary, which is I think what is causing this problem. Any recommendations as to how to fix this would be amazing, I've spent hours on this.
This error is probably due to linking against the wrong Python library. Make sure your extension as well as the Boost Python library are linked against the Python installation you are using to import the module.
On Linux you can check against which libraries you've linked with ldd. On OS X otool -L does the same thing. So, for example
otool -L libpcap_ext.so
otool -L /path/to/libboost_python-mt.dylib
should list the Python library they are linked against.
With CMake you can use the variable PYTHON_LIBRARY to change which Python library is used. As an example, on the command line you can set it with
cmake -DPYTHON_LIBRARY="/path/to/libpython2.7.dylib" source_dir
Lastly, on OS X a quick and dirty way (i.e. without recompiling) to change the dynamically linked libraries is install_name_tool -change.