haskell leksah hello-world
Asked Answered
C

3

8

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 functionmain' 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 :-)

Cadency answered 12/1, 2011 at 10:13 Comment(0)
C
15

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.

Confucianism answered 12/1, 2011 at 10:27 Comment(0)
I
6

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
Itinerant answered 12/1, 2011 at 10:24 Comment(2)
Well, I can't say for sure what the best practice is, but: in general, I limit my exports when I have a reasonably good idea that I've formed a cohesive module. Limiting your exports can be important for datatypes that you don't want people to access directly, on through a defined set of functions.Itinerant
And also, the compiler can optimize better, if you don't export anythig.Confucianism
B
6

"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.

Border answered 12/1, 2011 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.