Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running `cabal repl` with Top-level Functions

Tags:

haskell

cabal

I'm trying to learn to sandbox my Haskell projects with cabal.

I make extensive use of the command interpreter ghci, which imports top-level functions by default.

cabal repl also provides a command interpreter, but top-level functions are not imported.

How can I run cabal repl so that top-level constants and functions will be defined in the command interpreter?

Here's a minimal example:

-- somefile.hs
someConstant :: Int
someConstant = 5

main :: IO ()
main = undefined

Now, someConstant will be defined when I run ghci somefile.hs, but it won't be defined when I run cabal repl.

like image 586
Fried Brice Avatar asked Mar 22 '26 06:03

Fried Brice


1 Answers

If the module is one listed in your project (i.e. in your exposed-modules or other-modules sections):

:m *ModuleName

Otherwise:

:l somefile.hs

See also What's really in scope at the prompt? from the Fine Documentation.

like image 146
Daniel Wagner Avatar answered Mar 25 '26 01:03

Daniel Wagner



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!