Make Your Own Data Type

Everything after the equal sign is called the value constructor

MetricUnit is called the type constructor

In a new file MyData.hs

Meter has the type MetricUnit

Let's look at Meter , Liter , and KiloGram

Why did we get this error?

but our MetricUnit doesn't derive Show

print only works for things that derive Show

GHCi is trying to call the print function

So let's make our own function

We can't use our MetricUnit type unless a function accepts it

Write a simple function that takes in a MetricUnit, and returns its symbol

Try compiling it. What happens?

deriving (Eq)

GHCi is yelling at us because we used '=='

No instance for (Eq MetricUnit) arising from a use of `==' Possible fix: add an instance declaration for (Eq MetricUnit) In the expression: x == Meter

So MetricUnit should derive Eq in this case

data MetricUnit = Meter | Liter | KiloGram deriving (Show, Eq)

Play close attention to the syntax. To derive multiple typeclasses, you separate them by commas.