Installing packages

Hi there

So I have installed Purescript according to the book https://book.purescript.org/

My question is about package management.
I have read @justinw posts in relation to package management but I still fail to grasp how this is handled at system level, if that makes sense.

For example, I am used to Python Pip Install Packages (pip install) – I can launch it from any directory and that will install the package making it accessible from anywhere. In other words, if I run pip install pandas a bunch of stuff happens and then i can launch a repl and import Pandas as pd will work. Not so with Purescript… let me explain.

From what I tried it seems packages need to be reinstalled in each project directory, which needs to be init-ed first, but I am not sure if this is intended or I am doing something wrong.

Here’s a list of what I have done and results:

1. Create project as per the book

  • Navigate to my root directory (or any other directory that is NOT the project one)
  • spago repl
  • import Math
in module $PSCI
at <internal>:0:0 - 0:0 (line 0, column 0 - line 0, column 0)

  Unknown module Math

Then if id try spago install math I get:

[error] There's no "spago.dhall" in your current location.

If you already have a spago project you might be in the wrong subdirectory,
otherwise you might want to run `spago init` to initialize a new project.

2. Create project as per the book

  • Navigate to project directory
  • spago repl
  • import Math, throws error
in module $PSCI
at <internal>:0:0 - 0:0 (line 0, column 0 - line 0, column 0)

  Unknown module Math

3. Create project as per the book

  • Navigate to project directory
  • spago install math
  • spago repl
  • import Math, looks good! :blush:
> import Math
> 

What from my point of view should happen / would make sense is being able to install packages once, and use them system wide similar to pip install.

Is it me doing something wrong or is this a not supported feature? If the latter, is it planned, and how could I contribute?

thanks!

Think of spago install as npm install: they both install the dependency local to that particular project. Now, behind the scenes, Spago is saving a copy of that dependency in your cache folder. If you install that same package again in the future in some other project, it will copy the files from the cache to your local project directory rather than redownloading the files. Also, PureScript does not have a backend by default. So, when you download those files, you’re downloading the source code and recompiling them alongside of your project’s code. You’re not downloading the already-compiled-to-JavaScript files that you could then run via node ModuleName.js or something.

So, the right process for doing this is

mkdir newDir
cd newDir
spago init # this installs console, effect, prelude, and psci-support
spago install packageName # install other dependencies
spago repl

> import Path.To.Module
> 
2 Likes

This visual overview of Spago can also help: https://github.com/purescript/spago#visual-overview-what-happens-when-you-do-spago-build

Hey, thanks for the reply - ok this si all new to me so is super helpful! :smiley:

@JordanMartinez also related to package import:

If I launch spago repl and do:

import Data.List
import Data.Array

:type zip throws an error:

in module $PSCI
at :1:1 - 1:4 (line 1, column 1 - line 1, column 4)

  Conflicting definitions are in scope for value zip from the following modules:

    Data.Array
    Data.List



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

Now, when I go to the github link, the suggestion is to do

import package as P

When I try that however I get:

> import Data.List as dl
Unexpected token 'import' at line 1, column 1

It seems to work in my Main.purs file however, so I guess is just a repl issue?

I believe you can only use upper-case module names, ie.

- > import Data.List as dl
+ > import Data.List as DL
  > :type DL.zip

Oh man, I haven’t thought of that! @thomashoneyman

By the way, I’m reading your real world halogen, great stuff!

I’m trying to build a simple one page webapp as an intro project, trying to adapt an old repo that was written in PS 12.0 and Pux 1.0.0 to latest PureScript and halogen. To put it mildly im pretty stuck at the moment.

I am thinking to do real world together with the purescript book, but I’d like to try and build as I learn if I can. If is not too much to ask would you mind have a look at the repo and give some pointers? I’ll share a lowfi wireframe too as soon as I am back at my laptop…

Cheers

@ppq Basically Modules, Types, Data constructors, and type classes ALWAYS start with an uppercase letter.

module I.Must.Always.Start.With.Uppercase.Letter where

type SameHere = Int
newtype AlsoHereToo = NewtypeWrapper Int
data MeToo = DataConstructor

functionNamesMustStartWithLowercaseLetter :: Int -> Int
functionNamesMustStartWithLowercaseLetter x = x

valueNamesMustStartWithLowercaseLetter :: Int
valueNamesMustStartWithLowercaseLetter = 5

-- type variables must start with a lowercase letter
foo :: forall typeVariable. typeVariable -> typeVariable
foo x = x

class UppercaseMyFirstLetter

instance uppercaseMyFirstLetterFoo :: UppercaseMyFirstLetter Foo

foofoo 
  :: forall typeVariable
   . UppercaseMyFirstLetter typevariable 
  => typevariable 
  -> Int
foofoo _ = 4
1 Like

@ppq I’d recommend sharing the repo here on Discourse; I may be able to help with some pointers, but there are also plenty of other folks here who have lots of knowledge to share. That said, there’s no telling how busy people may be at a particular moment!

Also, as you get stuck with particular problems, you could post them as replies in the thread you create, or ask questions on Slack.

1 Like