Module structure
A module is simply a bunch of related functions, types and type classes. This makes a program a collection of modules. This helps organize your code and makes reusing some of the code easier.
Module header
Module declaration
This how we declare a new module and specify which of the functions or types are exported.
module Hello (greet, farewell) where
{- the module name can be a word or words separated by '.';
in this case it is just "Hello" -}
greet :: String -> String
greet n = "Hello " ++ n
farewell :: String -> String
farewell n = "Bye " ++ n
Module import
The syntax for import in Hamler is import <module name>
. This has to be done before defining any functions. One module can import as many as modules you wish, but there could be ambiguity when there are two things with the same name.
import Data.List --Modules are imported using their full names
import Data.Maybe (isJust, isNothing) -- We can choose which functions to import
import Data.Funtion as F
-- We can deal with ambiguity by adding an alias. This means we need to add "F." before every function that is exposed from Data.Function to specify that it is from this module
import Prelude hiding (fst) -- The Prelude is imported by default. By hiding `fst`, we can define our own version.
当前内容版权归 hamler-lang 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 hamler-lang .