Haskell: Parse error: module header, import declaration or top-level declaration expected

From a newbie to future newbies: The interactive environment ghci would lead you to believe that you can punch some expressions into an .hs file and run the thing (in a similar fashion to languages like swift and ruby). This is not the case.

Haskell needs an entrypoint called main. Quoting:

Here is a simple program to read and then print a character:

main :: IO ()
main =  do c <- getChar
           putChar c

The use of the name main is important: main is defined to be the entry point of a Haskell program (similar to the main function in C), and must have an IO type, usually IO ()

Source: https://www.haskell.org/tutorial/io.html


You can't just put any expression in a hs file.

As the error message says, you need a declaration here. For example:

main =
    print (fst (1,2)) >>
    print (snd (1,2))