Modules

A module is a compilation unit which exports types, functions, type classes and other modules.

Module Declaration and Export

The name of a module must start with a capital letter.

  1. -- Declare a module and export all the types and functions
  2. module MyMod where
  3. -- Declare a module and export some types or functions
  4. module MyMod (Maybe(..), add) where
  5. data Maybe a = Just a | Nothing
  6. add :: Integer -> Integer -> Integer
  7. add x y = x + y

Main

  1. -- Main
  2. module Main where
  3. import Prelude
  4. main = println "Hello World"

Import

  1. import Data.List
  2. import Data.Map (keys, values)
  3. nth 1 [1..10] -- 1
  4. keys #{"key" => "val"} -- ["key"]
  5. values #{"key" => "val"} -- ["val"]
  6. -- Qualified Imports
  7. import Data.Set as Set
  8. import Data.Map as Map
  9. Map.get "foo" #{"foo" => "bar"}