


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Function names, variable names starts with lowercase letter - followed by zero or more digits, underscores ( ) upper or lowercase letters, forward quotes (´). For example, x 1 , x′, x 1 , x′′.
Datatype and datatype constructor names start with uppercase letters and are otherwise like functions and variable names. For example, Bool, String, Int , True, False.
Keywords case, class, data, default, deriving, do, else, if, import, in , infix, infixl, infixr, instance, let, module, newtype, of , then, type, where.
Each function definition must begin in the same column.
a = b + c where b = 1 c = 2
d a = a* 2
a = b + c where {b = 1; c = 2}
d a = a* 2
Line comments start with ”–” and continue to the end of the line. For exam- ple, f x = x + 1 − −dumbf unction Nested comments are of the form {− · · · −}
The following code has the same effect as the ex. 1
a = let b = 1 c = 2 in b + c
Here’s another version of it.
a = b + c where b = 1 c = 2
Meaning of let-in. let x = t 1 in t 2 means t 2 [x := t 1 ] where,
and t 2 [x := t 1 ] - evaluate expression t 2 where all free occurrences of x get the value of expression t 1. Note that ”:=” is a capture-avoiding substitution
let x = 1 in let x = 2 in x
we can elaborate on it ∀x : Int, ∀x : nat.x ≥ 0. Choose arb. y ∈ int and show ∀x : Int, ∀x : nat.x ≥ 0[x := y] ; ∀x : nat, x ≥ 0
A code fragment in an imperative language
if x > 0 then y := x else y:= (-x)
In C and C++ there is a conditional expression
(&&),(||) :: Bool -> Bool -> Bool
True && x = x False && _ = False
True || x = True False || x = x
False && infinity
In Haskell, we have lazy evaluation so if we try to evaluate the above expression it evaluates to False. But in eager evaluation it will loop forever. There is a little bit of asymmetry here - Infinity and False will not terminate but evaluate to infinity.
not ::Bool -> Bool not True = false not False = True
otherwise::Bool not otherwise = True.