Different behavior of cabal repl for library vs. executable
Asked Answered
G

1

7

Using cabal repl seems to do nothing at all when used on library projects, but works fine for executable projects. Is this expected behavior that I just don't understand?

If I have a file containing simply

go = putStrLn "test"

and use cabal init with all the defaults (but choose "library" as the type), then running cabal repl just produces the some text about configuring and preprocessing the library and never enters a REPL environment. The exact same steps, but with "executable" selected as the type, puts me right into GHCi as expected.

The code works fine when loaded directly into GHCi.

Gable answered 2/6, 2014 at 18:23 Comment(4)
Have you specified that file as an exposed module? I think cabal repl will only load it if you have it specified, but that's an untested guess.Farfamed
@Farfamed Thanks for the idea, but that doesn't seem to be the problem. I tried it both with and without the module line and got the same result.Gable
Well you'd need a named module, but you also need to specify it in you project's cabal file as an included module. Have you tried that too?Farfamed
That was it, you were right the first time. If you want to create a real answer I'd be happy to mark it as accepted.Gable
F
7

For cabal repl to load your modules, you have to first name them in code and then specify them in your project's .cabal file as exposed:


-- MyModule.hs
module MyModule where

go = putStrLn "test"

-- MyProject.cabal
name: MyProject
-- other info ...

library
    exposed-modules: MyModule
    -- other options ...

Then when you run cabal repl, it'll have access to everything in your sandbox (if present) and the exposed modules. It might also work if you specify them as other-modules instead of exposed-modules, but I haven't tried that one out.

Farfamed answered 2/6, 2014 at 18:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.