02. HC2 ‐ Haskell Chapter 2 Practical Tasks: Types and Functions - wimsio/universities GitHub Wiki
HC2T1 - Task 1: Checking Types in GHCi
-
Open GHCi and check the types of the following expressions:
42
3.14
"Haskell"
'Z'
True && False
-
Write down the expected types before checking in GHCi.
HC2T2 - Task 2: Function Type Signatures
-
Write function signatures for the following functions:
- A function
add
that takes twoInt
values and returns their sum. - A function
isEven
that takes anInt
and returns aBool
indicating if it's even. - A function
concatStrings
that takes twoString
values and returns their concatenation.
- A function
-
Implement these functions.
HC2T3 - Task 3: Immutable Variables
-
Define the following immutable variables in Haskell:
myAge
as anInt
piValue
as aDouble
greeting
as aString
isHaskellFun
as aBool
-
Try modifying one of the variables and observe what happens.
HC2T4 - Task 4: Converting Between Infix and Prefix Notations
-
Use prefix notation for the following infix expressions:
5 + 3
10 * 4
True && False
-
Use infix notation for the following prefix functions:
(+) 7 2
(*) 6 5
(&&) True False
HC2T5 - Task 5: Defining and Using Functions
- Write a function
circleArea
that takes aFloat
radius and returns the area of the circle. - Write a function
maxOfThree
that takes threeInt
values and returns the maximum. - Test your functions with different inputs.
Int
vs Integer
HC2T6 - Task 6: Understanding - Define an
Int
variablesmallNumber
with the value2^62
. - Define an
Integer
variablebigNumber
with the value2^127
. - Try to evaluate
2^64 :: Int
in GHCi and note the result.
HC2T7 - Task 7: Boolean Expressions
- Write Boolean expressions that evaluate to:
True
using&&
False
using||
True
usingnot
- A comparison that returns
False