We're declaring two "new types" one named Fahrenheit and the other named Celsius, both are really just Floats. Then we declare two conversion functions, far2cel and cel2far, to handle marshaling a Fahrenheit temperature to a Celsius. We are using the *, -, and + operators from the Num class and the / operator from Fractional, by declaring our Fahrenheit and Celsius newtypes to derive from Fractional and from Num in conjunction with the -XGeneralizedNewtypeDeriving GHC option. Neat

Note, though, that the Num instance for Farhrenheit requires that when you want to multiply or divide stuff, you have to put in Fahrenheit and get Fahrenheit. For example:> (medianTemp - minTemp) / (maxTemp - minTemp)will have type Fahrenheit as well, although it is actually a unitless fraction.

Note that the module does not export the data constructor for temp; you must use the degC and degF functions to create values of this type, which forces the programmer to explicitly say what type his units are when using constants:

> degF 55 - degC 8

If you use -XPostfixOperators, you can even use these in postfix format, though I'm not sure it's any less clunky: