08. HC8 ‐ Haskell Chapter 8 Practical Tasks: Creating‐non‐parameterized‐types - wimsio/universities GitHub Wiki

  1. HC8T1: Create a type synonym called Address for String and a type synonym called Value for Int. Define a function generateTx :: Address -> Address -> Value -> String that takes two addresses and a value and returns a string concatenating these.
  2. HC8T2: Define a new type PaymentMethod with the constructors Cash, Card, and Cryptocurrency. Create a Person type that includes a name, address (tuple of String and Int), and a payment method. Create a person bob who pays with cash.
  3. HC8T3: Define a type Shape with constructors Circle Float and Rectangle Float Float. Create a function area :: Shape -> Float that calculates the area of the shape. Calculate the area of a circle with radius 5 and a rectangle with sides 10 and 5.
  4. HC8T4: Define a new type Employee using record syntax with fields name :: String and experienceInYears :: Float. Create an employee richard with 7.5 years of experience.
  5. HC8T5: Define a type Person using a record syntax that includes name :: String, age :: Int, and isEmployed :: Bool. Create a person1 who is employed, and a person2 who is unemployed.
  6. HC8T6: Define a type Shape using record syntax with fields center :: (Float, Float), color :: String, and radius :: Float for circles, and width :: Float, height :: Float, and color :: String for rectangles. Create an instance of Shape for a circle and a rectangle.
  7. HC8T7: Define a new type Animal using data with constructors Dog String and Cat String. Create a function describeAnimal :: Animal -> String that describes the animal. Create instances for a dog and a cat.
  8. HC8T8: Using type synonyms, create a type synonym Name for String and a type synonym Age for Int. Define a function greet :: Name -> Age -> String that takes a name and age and returns a greeting.
  9. HC8T9: Define a type Transaction with fields from :: Address, to :: Address, amount :: Value, and transactionId :: String. Define a function createTransaction :: Address -> Address -> Value -> String that creates a Transaction and returns the transaction id.
  10. HC8T10: Using deriving Show, define a type Book with fields title :: String, author :: String, and year :: Int. Create a Book instance for a book and print it using the Show instance.

Finished. Congratulations! Get your progress token here