[Haskell-beginners] "module Main" from hitchhikers guide cd fit example

Daniel Fischer daniel.is.fischer at web.de
Wed Jul 28 09:35:36 EDT 2010


On Wednesday 28 July 2010 10:55:25, Johann Bach wrote:
> On Wed, Jul 28, 2010 at 1:42 AM,  <skip at pobox.com> wrote:
> > I'm trying to work my way through the hitchhikers guide, knowing
> > nothing about Haskell (my day-to-day programming is in Python with a
> > sprinkling of C).  I've installed a binary distribution of Haskell
> > Platform on my Mac. GHCi reports version 6.12.3.  I'm currently in "3
> > Chapter 2: Parsing the input".  I'm stuck on the module Main
> > definition.  In hello.hs it works as expected:
>
> The "module Main were" has to be the first line in the file.

The first *code* line.
Pragmas, comments and whitespace can preceed it.

Generally, a module starts with

-- LANGUAGE pragmas
-- OPTIONS_TOOL pragmas
-- Module comment
-- Module Header
-- Imports

then come the definitions you make.

Pragmas and imports appear of course only if needed.
The module comment for haddocks is optional, but if you distribute a 
library, it's good practice to have one.

The module header,
module Foo (exportlist) where
, is optional, if you omit it, "module Main (main) where" is assumed.
If you omit the export list ("module Foo where"), all top-level bindings 
are exported.




More information about the Beginners mailing list