Lab Report - 4
Lab Report - 4
Lab Report – 4
Name : Mridhulaa S S
Roll No: 21040
Class: CSE - A
TYPES AND TYPECLASSES :
1. Create a data type called TrafficLight that stores different traffic colors using sum
type.
Syntax:
Output:
2. Create a record by defining a data type called car that stores company, model, year,
price, and color. Also print it using suitable deriving instance
Syntax:
Output:
3. Create a type Day for days of the week and derive instances for (Eq, Ord, Show,
Read, Bounded, Enum)
• isWednesday, which takes a day of the week and returns True if it’s Wednesday
and False otherwise.
• nextDay, which takes a day of the week and returns the day of the week that
comes after it.
Syntax:
Output:
Output:
4.Write a new function using suitable typeclass to decide if a value is an element of a list.
Syntax:
Output:
Syntax:
Output:
6. Write a function isElem using suitable typeclass and Make sure the following test
cases pass:
isElem 0 [] == False
Output:
7. Use suitable typeclass and create instances to print the Characters: A|B|C|D|E. (note:
for any other characters it should print as “not printable”)
Syntax:
Output:
8. Create a datatype Weekday for days of the week. Define a function workday which
takes a day of the week and returns True if it’s working and False otherwise.
Syntax:
Output:
9. Create a 'YesNo' type class. Define a function yesno which defines Boolean semantics
for all different types.
Syntax:
Output: