Modules

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.

-- Declare a module and export all the types and functions
module MyMod where

-- Declare a module and export some types or functions
module MyMod (Maybe(..), add) where

data Maybe a = Just a | Nothing

add :: Integer -> Integer -> Integer
add x y = x + y

Main

-- Main
module Main where

import Prelude

main = println "Hello World"

Import

import Data.List
import Data.Map (keys, values)

nth 1 [1..10]            -- 1
keys #{"key" => "val"}   -- ["key"]
values #{"key" => "val"} -- ["val"]

-- Qualified Imports
import Data.Set as Set
import Data.Map as Map

Map.get "foo" #{"foo" => "bar"}