Reputation: 5897
Here is my basic program, but it states the function 'main' is not defined in module 'Main' how can I fix this?
here is my program
main = do
-- variable
a <- getLine
putStrLn a
Upvotes: 3
Views: 5867
Reputation: 32455
This error message means simply that the compiler didn't find a definition of your function main
.
To run your compiled program, rather than interact with it in ghci (which I'd recommend you do as a beginner), you need main::IO ()
.
If you don't give your module a name, it automagically does the equivalent of inserting module Main where
at the top of your file.
I can't think of any way to produce this error other than to
--
or {-
other comment syntax -}
main
incorrectly(
Although your question appears to show incorrect indentation, that's because this site does not treat tabs as 8 characters wide. I suspect you indented the main
by four spaces to get it to format as code in your question. In any case the compiler didn't give an error message consistent with an indentation error.
I'd like to recommend you use spaces rather than tabs for indentation, as it's unfailingly irritating to have to debug the whitespace of your program.
Most editors can be configured to turn a tab key press into an appropriate number of spaces, giving you the same line-it-up functionality with none of the character count discrepancies.
)
Upvotes: 1
Reputation: 103
Your code is missing indentation, Haskell uses indentation to figure out where a block ends.
main = do
a <- getLine
putStrLn a
Above is the proper indented form of your code; you should probably read the article here which explains it far better than I.
Upvotes: 6