67 lines
2.9 KiB
Haskell
67 lines
2.9 KiB
Haskell
-- Module declaration with explicit exports: exports only specified items, hiding others.
|
|
-- Here, exporting a function, a type with all constructors, a class, and a module re-export.
|
|
module ExampleModule
|
|
( myFunction -- Exports the function myFunction
|
|
, MyType(..) -- Exports type MyType and all its constructors/patterns
|
|
, class MyClass -- Exports the class MyClass
|
|
, module Data.Maybe -- Re-exports everything from Data.Maybe
|
|
) where
|
|
|
|
-- Simple import: imports all exported items from Prelude unqualified.
|
|
import Prelude
|
|
|
|
-- Empty import list: imports nothing explicitly, but allows qualified access if qualified.
|
|
import Prelude ()
|
|
|
|
-- Specific imports: imports only listed items unqualified.
|
|
import Prelude (not, (&&)) -- Imports not and && operators.
|
|
|
|
-- Import type with specific constructors: imports MyType but only Con1 and Con2.
|
|
import ExampleModule (MyType(Con1, Con2)) -- Imports Con1 and Con2 for MyType.
|
|
|
|
-- Import type with all constructors: imports MyType and all its constructors.
|
|
import ExampleModule (MyType(..)) -- Imports MyType and all constructors/patterns.
|
|
|
|
-- Import class: imports the class MyClass.
|
|
import ExampleModule (class MyClass) -- Imports MyClass class.
|
|
|
|
-- Hiding specific items: imports all from Prelude except not and &&.
|
|
import Prelude hiding (not, (&&)) -- Excludes not and && from import.
|
|
|
|
-- Qualified import: imports all from Data.List qualified, access via Data.List.name.
|
|
import qualified Data.List
|
|
|
|
-- Qualified with hiding: imports qualified, excluding intersect.
|
|
import qualified Data.List hiding (intersect) -- Excludes intersect, others via Data.List.
|
|
|
|
-- Qualified with specific items: imports only sort and length qualified.
|
|
import qualified Data.List (sort, length) -- Access via Data.List.sort, Data.List.length.
|
|
|
|
-- Import as alias: imports all from Data.Map unqualified, but alias for qualified use.
|
|
import Data.Map as M -- Unqualified access, or M. for qualified.
|
|
|
|
-- Qualified as alias: imports qualified with alias DM.
|
|
import qualified Data.Map as DM -- Access via DM.name.
|
|
|
|
-- Qualified as alias with specific items: imports only lookup and insert as DM.
|
|
import qualified Data.Map (lookup, insert) as DM -- DM.lookup, DM.insert.
|
|
|
|
-- Qualified as alias hiding: imports qualified as DM, hiding delete.
|
|
import qualified Data.Map hiding (delete) as DM -- Excludes delete, others via DM.
|
|
|
|
-- ghci -i path/to/my/custom/module/ Executable.hs
|
|
import MyCustomModule -- Imports from specified source file.
|
|
|
|
-- Import safe: imports only safe exports (no unsafePerformIO etc.).
|
|
import safe System.IO.Unsafe -- Imports only safe items.
|
|
|
|
-- Qualified safe: imports qualified and safe.
|
|
import safe qualified System.IO.Unsafe as Unsafe -- Unsafe.name, only safe items.
|
|
|
|
-- Import instances: instances are imported automatically with types/classes (no explicit syntax).
|
|
|
|
-- Re-exporting: as shown in module header, use module OtherModule to re-export.
|
|
|
|
-- Note: Exports control visibility; if not in export list, hidden unless open module.
|
|
|