Save
...
12.0 Fundamentals of functional programming
12.3 Functional programming languages
12.3.1 Haskell
Save
Share
Learn
Content
Leaderboard
Share
Learn
Cards (91)
Haskell is a statically typed, purely functional programming
language
Lazy evaluation in
Haskell
means expressions are evaluated only when their values are needed.
Haskell uses type inference to often infer the types of variables and
expressions
In Haskell, data is
immutable
, meaning it cannot be changed once created.
The functional paradigm in Haskell makes programs easier to
reason
Static typing in Haskell reduces
runtime
type errors.
Lazy evaluation in Haskell improves
performance
What does the Haskell function `doubleMe x = x + x` do?
Doubles the input
Haskell is a purely functional programming language, meaning programs are composed of pure
functions
Haskell's
static typing
checks types at compile time.
Haskell is a statically typed language where types are checked at
compile
Haskell programs are composed of
pure functions
.
What are three other key features of Haskell besides static typing and pure functions?
Lazy evaluation, type inference, immutable data
Order the Haskell features from most to least frequently mentioned in the study material.
1️⃣ Functional paradigm
2️⃣ Static typing
3️⃣ Lazy evaluation
Lazy evaluation improves performance by evaluating
expressions
only when needed.
Lazy evaluation ensures that expressions are evaluated only when their
values
are needed.
What is the result of the Haskell expression `doubleMe 5` where `doubleMe x = x + x`?
10
10
10
Haskell's type inference allows it to often infer the types of variables and
expressions
Match the Haskell feature with its benefit:
Immutable data ↔️ Prevents unexpected side effects
Type inference ↔️ Simplifies code
What does the Haskell function `doubleMe x = x + x` do?
Doubles its input
A type signature like `Int -> Int` means the
function
takes an integer and returns an integer.
What are the three types of expressions in Haskell?
Value, function, operators
The expression 2 + 3</latex> in Haskell evaluates to
5
5
5
.
Declarations in Haskell introduce new
identifiers
What does the declaration
x
=
x =
x
=
5
5
5
in Haskell do?
Assigns value 5 to x
Steps to define a function in Haskell
1️⃣ Declare the function name
2️⃣ Specify the type signature
3️⃣ Define the function parameters
4️⃣ Write the function expression
What does the function
d
o
u
b
l
e
M
e
:
:
I
n
t
−
>
I
n
t
doubleMe :: Int - > Int
d
o
u
b
l
e
M
e
::
I
n
t
−
>
I
n
t
do?
Doubles an integer
A type signature
I
n
t
−
>
I
n
t
Int - > Int
I
n
t
−
>
I
n
t
means the function takes an integer and returns an integer.
A single-line comment in Haskell starts with
--
What type does Haskell infer for
x
=
x =
x
=
42
42
42
?
`Int`
Pure functions in
Haskell
always return the same output for the same input.
Haskell uses lazy evaluation, which means expressions are evaluated only when their values are
needed
What is one benefit of static typing in Haskell?
Fewer runtime errors
Haskell can automatically infer the
types
of variables and expressions.
What is the functional paradigm in Haskell focused on?
Pure functions
The function
d
o
u
b
l
e
M
e
:
:
I
n
t
−
>
I
n
t
doubleMe :: Int - > Int
d
o
u
b
l
e
M
e
::
I
n
t
−
>
I
n
t
in Haskell doubles an integer
Single-line comments in Haskell start with
`--`
.
What type does Haskell infer for
y
=
y =
y
=
3.14
3.14
3.14
?
`Double`
Recursion in Haskell ensures pure functional behavior by not modifying
state
.
To define a recursive function in Haskell, you need a base case and a recursive
step
See all 91 cards