📘
HPM Education - Haskell
  • Introduction to Haskell
  • Introduction
    • Functions
    • Functional Programming vs Imperative Programming
    • Installing Haskell
    • Haskell Modules
    • Loading Modules into GHCi
    • Expressions
    • Laziness
    • Immutability
  • Types in Haskell
    • Introduction
    • Basic Types
    • Static Type Check
    • Polymorphic and Overloaded Types
    • Data Structure Types
      • Lists
        • List Functions
      • Tuples
    • Function Types
      • Curried Functions
      • Partial Application
  • Defining Functions / Working with Functions
    • The Layout Rule
    • Local Definitions
    • The Infix Operator
    • Conditionals
      • If-then-else Statements
      • MultiWayIf
      • Guarded Equations
      • Case-of Statements
    • Pattern Matching
      • Tuple Patterns
      • List Patterns
    • Lambda functions
    • Function Operators
  • List Comprehensions
    • List Comprehensions
  • Higher-order Functions
    • Introduction
    • The map Function
    • The filter Function
  • Recursion
    • Introduction
    • 4 Steps to Defining Recursive Functions
    • Recursion Practice
    • Folds
      • Fold Right (foldr)
      • Fold Left (foldl)
  • Cutom Types
    • Declaring Types
      • Type Synonyms
      • Data Declarations
      • Newtype declarations
  • Type Classes
    • Introduction
    • Basic Classes
      • Eq – Equality Types
      • Ord – ordered types
      • Show – Showable Types
      • Read – readable types
      • Num – Numeric Types
      • Integral – Integral Types
      • Fractional – Fractional Types
      • Enum – Enumeration Types
    • Derived Instances
    • Exercise – Making a Card Deck Type
  • Interactive Programming
    • Introduction
    • Input / Output Actions
    • Sequencing Actions
    • Exercise - Numbers Guessing Game
  • Functors, Applicatives and Monads
    • Introduction
    • Functors
    • Applicative Functors
    • Monads
      • Maybe Monad
      • List Monad
      • Monad Laws
  • References / Further Reading
Powered by GitBook
On this page

Was this helpful?

  1. Introduction

Haskell Modules

Haskell code is organised into modules, which are files that contain the Haskell source code. Each module corresponds to one single file, and the standard extension for Haskell modules is .hs. Each module should start with the name of the module which is also the same name of the corresponding file, e.g. module Triple.hs:

module Triple -- module name
(
    triple -- module interface (what is explicitly exported)
) where

{- Module contents -}
triple x = 3 * x -- function declaration

First, we have the module name Triple, followed by the module interface wrapped in parentheses. The module interface states what gets exported from this module, i.e. if this module is imported somewhere else, thetriplefunction is the only thing that would be usable from this module. If we had another function declared in the module contents (e.g. quadruple), that function would not be exported unless specified in the existing module interface. However, the module interface is optional, and if omitted, all the declarations from the module will be exported.

Comments serve the purpose of documenting our code and anything we put in comments will not be evaluated in the program. Haskell comments can be single-line and multi-line – single-line comments start with --, and multi-line comments are wrapped between {- -}. Any comments in this guide will also follow the same format.

PreviousInstalling HaskellNextLoading Modules into GHCi

Last updated 2 years ago

Was this helpful?