Ghci - import my own module from local haskell sourcefile

Greetings…
I made myself a Shapes.hs source file as described in: Modules - Learn You a Haskell for Great Good!.

I cannot import it from gchi. Some slightly older tutorial documentation says I can. I think this tutorial expects that you can.
I want to use import not :load - the real experience :slight_smile:

I am using an environment created via ghcup and stack new, stack setup

Prelude> import Shapes

<no location info>: error:
    Could not find module ‘Shapes’
    It is not a module in the current program, or in any known package.

My Shapes.hs file is in the same ./src/ directory as the examples Lib.hs file. I can import Lib.hs directly from ghci>

I must be missing some configuration incantation…

> ghci -W
GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help
Prelude> import Lib
Prelude Lib> 

The following works from the project root

> stack build
> stack exec LearnYouAHaskell-exe
Circle (Point 0.0 0.0) 99.0

Main.hs:

module Main where

import Lib
import Shapes

main :: IO ()
main = print $ baseCircle 99

Is Shapes listed in other-modules (or whichever syntax is used in .stack files)?

Can ghci be directed by the environment to look in the src/ directory for libraries to import?

It seems that stack ghci sets up a ghci with a project environment. Which seems to work.

In the GHCI section of the stack docs:

stack ghci allows you to load components and files of your project into ghci. 
It uses the same TARGET syntax as stack build, and can also take options
like --test, --bench, and --flag. 
Similarly to stack build, the default is to load up ghci with all libraries and executables in the project.
1 Like