Agenda

<aside> 📌 Reminders

Introduction to Haskell


Prerequisites

Editor

Haskell Basics

Defining a variable:

varName :: varType -- This is optional, Haskell will infer type
varName = varValue

-- OR
varName = varValue

-- Variables must be initialized at time of declaration
-- The following will not work
newVarName :: newVarType
-- Missing initialization!!

Defining a function

funcName :: arg1Type -> arg2Type -> ... -> argNType -> returnType
funcName arg1 arg2 ... argN = functionBody

-- Like before the first line is optional

List:

-- Creating a list
		x:xt
--  ^  ^
--  |  | __ rest of list (must be list not single element)
--  | __ first element

-- Deconstructing a list (suppose xs = x:xt)
head xs -- returns x
tail xs -- returns xt

-- Other list functions
null xs -- returns True iff xs is empty, False otherwise

Pattern matching:

f pattern1 = resultForPattern1
f pattern2 = restulForPattern2
.
.
.

-- Useful patterns: `[]` matches the empty list `(x:xt)` matches non-empty list

If-else

if cond then stmt else otheStmt

list concatenation

list1 ++ list2

Lab exercise