Learn the basics of Eta
As a first step, let's understand the Eta modules and packages at a higher-level.
An Eta package consists of modules and each module is defined in a single file with the .eta extension. An Eta module or program is free to import other Eta modules from other packages.
Module specification should be at the top of the source file. Every Eta program is a collection of modules. Each module contains functions and types.
1 2 3 4 | module Main where
main :: IO ()
main = putStrLn "You declared a main module!"
|
NOTE: Module names always start with a capital letter.
An Eta program consists of bindings. A binding is an association between a name or identifier and a value. Other languages call these variables because you can set new values to the variable over time.
In Eta, bindings are immutable and cannot be set to a new value once they've been defined. Bindings in Eta can be thought of as constant variables from other languages.
1 2 | fullName :: String
fullName = "Harry Potter"
|
Defining a function in Eta is describing what it does using other functions as building blocks.
1 2 | double :: Int -> Int -- function declaration
double n = 2*n -- function definition
|
Defining functions can be done in multiple lines.
1 2 3 4 | xor :: Bool -> Bool -> Bool
xor True True = False
xor False False = False
xor x y = True
|
NOTE: Function declaration is optional in Eta since it has a global type inference which we are going to cover in a later chapter.