Hello,
As part of my exercise, I have to create an instance of the show typeclass for a given data type defined as:
- type stat = (String, Int)
If it was a data type, like:
- data TrafficLight = Red | Yellow | Green
It would be as simple as doing:
- instance Show TrafficLight where
- show Red = "Red light"
- show Yellow = "Yellow light"
- show Green = "Green light"
However, I do not know how to declare the instance for a type, and then how to access its elements (String and Int).
This is what I have so far, which does not work:
- instance Show Stat where
- show stat(a,b) = a
instance Show Stat where
show stat(a b) = b
(imagine, for example, I desire to write" the value of "String" is "Int").
Thanks,