Convenience questions about the REPL

I’m using the REPL to play around with PS. :slight_smile: I gues two things would make this a lot more convenient for me:

  1. When I am in the reply and I want to use some definition from a little personal file I’ve written (for example Test/MySolutions.purs), then I import the file. So far, so good. But now I add something to Test/MySolutions.purs , then in order to make use of these changes to the file I exit the REPL and only on re-entering the REPL spago has pre-compiled my stuff in the file. Maybe I do it totally wrong, it would be much easier if I could say in the REPL: Hey, re-compile file test/MySolutions.purs here and now.

  2. (Somewhat complementary to the former:) Every time I start the REPL, I have to type a few import lines before I can start playing with my definitions, e.g.

     import Prelude
     import import Data.AddressBook
     import Test.MySolutions

    Does something like a startup file exist which I could put these imports in?(*)

Thanks in advance for pointers if there are any.

(*) I looked a bit around for this and found in the spago source the follwoing line (in REPL.hs): "Optional .purs files to load on start"

but to my surprise spago repl --help doesn’t show this option.

Well, for #1, there’s a REPL command for that! :reload or just :re for short.

I don’t have a good solution for #2 though. I usually use the REPL in the terminal portion of VS Code, which has a feature that you can highlight some code send it to your terminal (it’s <Alt>+<Enter> with my setup). So I’ll just go to the top of my file, highlight all my imports and send them to the REPL, which is an annoying extra step, but less work than typing all the imports manually.

1 Like

:reload is brilliant! It helps me not to exit and restart the REPL, therefore issue #2 lost its pressing importance. :slight_smile:


1 Like

Unless I’m misunderstanding what you’re trying to achieve, the .purs-repl files can be used for this.

Put a .purs-repl file in your project’s root directory and put all of your input statements in that. Then when you run spago repl from your project’s root directly, it it bring all of those imports into scope.

If you have a custom project prelude (./src/MyPrelude.purs for a module called MyPrelude for example) with other extra helper functions you like also, then you can also put import MyPrelude into your ./.purs-repl file also so that those helpers are brought into scope when you launch (again, launch from your project’s root directory :slight_smile: )


(and along with any custom prelude, you can also add

import MySolutions1 as Sol1
import MySolutions2 as Sol2
-- etc

…also. So that each time you launch a REPL from the root directory, you’ll have all of your previous work in scope also (Sol1.myFunction, Sol2.someAction, etc.)

Thanks @and-pete! That’s exactly what I was looking for.

Is that documented anywhere that you know of? That’s a really neat feature!


$ spago repl
PSCi, version 0.14.5
Type :? for help

> :?
The following commands are available:
    :reload                   Reload all imported modules while discarding bindings

Thanks, but I was actually asking about the .purs-repl file that @and-pete was talking about where you can make the REPL import modules automatically

1 Like

Yes ,the .purs-repl file is certainly worth being documented ! It’s (for me) pretty cool!

It is mentioned at in the “Getting Started” page, though it might be better to make it more prominent. It really is a time saver.


It’s been documented in my repo for a while now: