When I create a .hs file with the following code and load it to ghci using :l, the file loads, but I receive the error <interactive>:1:1: error: Variable not in scope: symbol if I ask for the type of symbol. I am aware that this means that I'm using a name which is not defined in the place in which I'm attempting to use it, but I cannot see what is wrong with the code:
module MyData
(MetricUnit(..),
ImperialUnit(..),
Measurement(..),
convert)
where
data MetricUnit = Meter | Liter | KiloGram
deriving (Show, Eq)
data ImperialUnit = Yard
| Gallon
| Pound
deriving (Show, Eq)
data Measurement = MetricMeasurement Double MetricUnit
| ImperialMeasurement Double ImperialUnit
deriving (Show)
symbol :: MetricUnit -> String
symbol Meter = "m"
symbol Liter = "L"
symbol KiloGram = "kg"
convert (MetricMeasurement x u)
| u==Meter = ImperialMeasurement (1.0936*x) Yard
| u==Liter = ImperialMeasurement (0.2642*x) Gallon
| u==KiloGram = ImperialMeasurement (2.2046*x) Pound
convert (ImperialMeasurement x u)
| u==Yard = MetricMeasurement (0.9144*x) Meter
| u==Gallon = MetricMeasurement (3.7854*x) Liter
| u==Pound = MetricMeasurement (0.4536*x) KiloGram
convert, symbol), or did you add this to the code after this Answer by chi indicated you were missing it?, symbolpart. You can add to the Question that you've used it as per an Answer, but you're still getting the same error.convert, symbol)out of my question. But addingconvert, symbol)doesn't work, so can't be the solution.