Safe HaskellSafe-Inferred

Lessons.Lesson01

Description

Notes taken by Ugnė Pacevičiūtė

Module is a unit of compilation. A module can export values, functions,.. so they become accessible from other modules.

Core thing to remember: all values (not variables) are immutable!

Synopsis
  • i :: Integer
  • ii :: Int
  • c :: Char
  • s :: String
  • b :: Bool
  • f :: Integer -> Bool
  • add :: Integer -> Integer -> Integer
  • il :: [Integer]
  • cl :: [Char]

Documentation

i :: Integer Source #

First let's declare some values. In Integer is unbounded (or endless) integer value which does not depend on your computer's architecture so never overflows. The first line is a signature (`::` is a delimiter between a name and a type). The second line is a body.

>>> i + i == 84
True

ii :: Int Source #

An Int represents an integer which size respects your computer's architecture. Might overflow.

c :: Char Source #

A single character

s :: String Source #

A String (technically, a list of Chars)

b :: Bool Source #

A Boolean, might be True or False

f :: Integer -> Bool Source #

So, let's assume we know how to declare values, but what about functions? Functions and values are declared in a similar way, here we have a function which takes an Integer as a parameter and returns a Bool.

Values are functions which do not take any arguments!

>>> f 23
True
>>> f 19
False

add :: Integer -> Integer -> Integer Source #

This is a bit more sophisticated case: function takes two arguments.

>>> add 20 22
42

But what is we pass less arguments than needed? You get a function as a result!

>>> :t add 20
add 20 :: Integer -> Integer
>>> :t add
add :: Integer -> Integer -> Integer

This technique is called Currying

il :: [Integer] Source #

Another built-in type: a list. It has a special syntax

cl :: [Char] Source #

And, as it was mentioned a bit earlier, a String is a list of Chars.