Import a module from the current working directory

init.hs the library module has

module init where
data Suite = Clubs | Diamonds | Hearts | Spades deriving (Eq,Ord,Enum,Show)

main.hs, the input module has

module Main where
import init
main = do
  print (fromEnum Clubs)

Both modules are in the same directory, and the directory is not part of the path to Kabbalah.

When executed, runhaskell main.hsit throws an error like main.hs:2:8: parse error on input ‘init’.

What is the correct way to import a module into the current working directory without polluting global PATH / CABAL variables?

+4
source share
1 answer

Shouldn't the module name start with a capital letter? Replace initwith init:

module Init where
data Suite = Clubs | Diamonds | Hearts | Spades deriving (Eq,Ord,Enum,Show)

module Main where
import Init
main = do
  print (fromEnum Clubs)

Edit:
As mentioned by ØrjanJohansen :

Typically, the file should have a name after the module name, replacing dots in the module name using directory separators.

Quote Source

Init.hs.

+7

All Articles