I am completely new to PureScript and am doing chapter 3 of the Freeman book.
When I run spago repl
and type
> 1 + 3
Error found:
in module $PSCI
at :1:3 - 1:4 (line 1, column 3 - line 1, column 4)
Unknown operator (+)
See https://github.com/purescript/documentation/blob/master/errors/UnknownName.md for more information,
or to contribute content related to this error.
Seriously? If I run the repl in another directory, it works as expected.
What is going on?
1 Like
Hello and welcome to PureScript.
It’s a bit strange I guess but you have to import the prelude:
import Prelude
PureScript itself is a rather slim language and most things come with packages - and it happens that +
is only defined in one as well.
Luckily most of this basic stuff is packaged together in Prelude
but you have to import it as there is no auto-import of this.
EDIT: well I guess there is some auto-import now (just noticed it ) - if you see the import Prelude
after starting you are good to go.
I’m sure someone here knows exactly when this is used … cannot find it right now but I’ll keep looking
Ok I think when you do spago init
it should generate a .purs-repl
file that get’s loaded and this should include the import Prelude
part.
If you have no such file a default is used include the import.
So in the directory where it is not working for you is there such a file and what is it’s content?
There is no such file. And you’re right, the import Prelude
did it.
I just cloned the book repo.
Funny thing it works in other directories with no such file…
if you want you can add it (just add a single line import Prelude
) so that you don’t have to retype it.
I guess spago
will assume some default outside a project directory (spago.dhall etc. present).
That might be the case.
Thanks for the help, appreciate the swift response.
It might be nice to add a .purs-repl
file with the same content inside the book repo, as (+)
probably would have just worked without needing to be imported in that case.
2 Likes
So if that file is in the root of the repo, it will be found no matter were I start spago repl
?
1 Like
I think it needs to be in the same directory, so perhaps we could add one to each directory that you’re likely to be running the repl from?