3 ms·
In this case, Word8 applies nicely, but I'd like to point out that the argument doesn't fly either when something isn't nicely mapped to a type. E.g. (not check
by danieldk 14y ago
In this case, Word8 applies nicely, but I'd like to point out that the argument doesn't fly either when something isn't nicely mapped to a type. E.g. (not checked):
module Temperature (
TempCelsius
tempCelsius
) where
newtype TempCelsius = TempCelsius Double
absoluteMinimum :: Double
absoluteMinimum = -273.15
tempCelsius :: Double -> Maybe TempCelsius
tempCelsius t
| t < absoluteMinimum = Nothing
| otherwise = Just $ TempCelsius t
In other words, by hiding the constructor, you can control all access to a datatype. You could do the same with opaque pointers in C, etc.