bad news this morning, I was willing to try and use Leksah (nice looking application by the way) for continuing learning haskell.
I couldnt compile the "Hello World" example I found reading the leksah tutorial.
module Main (
main = putStrLn "Hello World"
) where
compilation-error: src\Main.hs:16:5: parse error on input
='`
and
module Main (
) where
main = putStrLn "Hello World"
compilation-error: src\Main.hs:1:0: The main function
main' is not exported by module Main'
What would you advise me to try something else ?
IMPORTANT EDIT: Now Leksah is shipped with a file Main.hs, loaded directly the first time you launch leksah, that contains a fully functionnal Hello World mini project. It has also minimalist unit test counter part. Great 开发者_开发知识库for beginners :-)
The text in the paranthesis after the module name is an export list. This means, that you have to put all functions in the program you want to export in there. But apart from this, you also have to define your main function somewhere. Try this:
module Main (
main
) where
main = putStrLn "Hello World"
PS: You can also remove the paranthesis and anything in there, than anything in your module is going to be exported.
Your second example is almost there, just remove the ()
from beside Main
. This is your export list for your module, which you have made empty (nothing in-between the parentheses). Because of that, main
isn't seen (because it's not exported).
You could also just export main:
module Main (main) where
"Is it good practice to export everything?" Definitely not. You don't want that implementation details like helper methods leak to the outside. Another example are value constructors, because there is no way to have sanity checks, default arguments etc for them. To overcome this, you use them only inside the module, and provide convenient and safe initialization functions for the outside.
精彩评论