I have three files (Play.hs
, Sudoku.hs
and Nim.hs
), and each one of those files has a main
.
I want to make a main
in Play.hs
to run one of those games (either Nim or Sudoku), like this:
main :: IO ()
main = do
putStrLn "1-Sudoku"
putStrLn "2-Nim"
putStrLn "choice----->"
let x=getLine
if x==1 then
....
else
...
You may call the
main
value from other modules just fine, as long as add the linemodule Nim where
to the top ofNim.hs
, and similarly forSudoku.hs
.Of course, if you have more than one
main
in scope, there will be ambiguity; but you can deal with ambiguity in the same way formain
as you do for other names by qualifying them...and if you're in the interpreter, start your program with
Play.main
.