klequis / zz-haskell-notebook

Notes from learning Haskell
1 stars 0 forks source link

Module #44

Open klequis opened 2 years ago

klequis commented 2 years ago

A module is the unit of organization that the Haskell programming language uses to collect together declarations of values, functions, datatypes, type classes, and type class instances. Any time you use import in Haskell, you are importing declarations from a module. Let us look at an example from the chapter exercises:

{-# LANGUAGE NoMonomorphismRestriction #-}
module DetermineTheType where
--              ^ name of our module

Here, we turn our Haskell source file into a module, and we name it DetermineTheType. We include a directive to the compiler to disable the monomorphism restriction before we declare the module. Also, consider the following example using import:

import Data.Aeson (encode)
--           ^ the module Data.Aeson
import Database.Persist
--            ^ the module Database.Persist

In the above example, we are importing the function encode declared in the module Data.Aeson along with any type class instances. With the module Database.Persist, we are importing everything it makes available.