Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load a file into Elm REPL?

Tags:

elm

For example: in this repo, https://github.com/evancz/elm-architecture-tutorial/ , how do I load one of the Elm files into elm repl, so I can evaluate functions, look at type signatures, etc ?

In Haskell I would use :l

like image 439
PizzaBeer Avatar asked Oct 15 '25 15:10

PizzaBeer


2 Answers

Unfortunately the examples on the GitHub link don't expose anything, so you cannot import from them as-is. Since you have access to source code you can of course modify the sources to support this, so read on :)

In general, it is done in repl by using command import

import SomeModule exposing (fun1, fun2)

SomeModule is the name of the module where to import, and fun1 and fun2 are functions to import. For importing all functions, use (..)

When the repl is started in the same folder as the modules, the import works. Maybe there's some option for repl to set the sources directory, but I could not find it.

But for something to be imported from a module, it needs to export it in the source file, like this for example

module SomeModule exposing (fun1, fun2)

like image 170
kaskelotti Avatar answered Oct 18 '25 14:10

kaskelotti


This would be better placed as a comment on kaskelotti's good answer above, but in order to have the module in a different folder from where you start the repl, you can update the elm.json file associated with your project, adding "YOUR_DESIRED_DIRECTORY" to the "source-directories" array.

Also note that the filename needs to match the module name in the export and import statements:

so that

module SomeModule exposing (fun1, fun2)

would require a file named SomeModule.elm (at least in my experience)

like image 29
alex.h Avatar answered Oct 18 '25 14:10

alex.h



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!