02. HC2 ‐ Haskell Chapter 2 Practical Tasks: Types and Functions - wimsio/universities GitHub Wiki

HC2T1 - Task 1: Checking Types in GHCi

  1. Open GHCi and check the types of the following expressions:

    • 42
    • 3.14
    • "Haskell"
    • 'Z'
    • True && False
  2. Write down the expected types before checking in GHCi.

HC2T2 - Task 2: Function Type Signatures

  1. Write function signatures for the following functions:

    • A function add that takes two Int values and returns their sum.
    • A function isEven that takes an Int and returns a Bool indicating if it's even.
    • A function concatStrings that takes two String values and returns their concatenation.
  2. Implement these functions.

HC2T3 - Task 3: Immutable Variables

  1. Define the following immutable variables in Haskell:

    • myAge as an Int
    • piValue as a Double
    • greeting as a String
    • isHaskellFun as a Bool
  2. Try modifying one of the variables and observe what happens.

HC2T4 - Task 4: Converting Between Infix and Prefix Notations

  1. Use prefix notation for the following infix expressions:

    • 5 + 3
    • 10 * 4
    • True && False
  2. Use infix notation for the following prefix functions:

    • (+) 7 2
    • (*) 6 5
    • (&&) True False

HC2T5 - Task 5: Defining and Using Functions

  1. Write a function circleArea that takes a Float radius and returns the area of the circle.
  2. Write a function maxOfThree that takes three Int values and returns the maximum.
  3. Test your functions with different inputs.

HC2T6 - Task 6: Understanding Int vs Integer

  1. Define an Int variable smallNumber with the value 2^62.
  2. Define an Integer variable bigNumber with the value 2^127.
  3. Try to evaluate 2^64 :: Int in GHCi and note the result.

HC2T7 - Task 7: Boolean Expressions

  1. Write Boolean expressions that evaluate to:
    • True using &&
    • False using ||
    • True using not
    • A comparison that returns False

Finished. Congratulations! Get your progress token here