
Hi Daniel,
Instead of raising an error it's more secure to return a Maybe value.
date :: Int -> Maybe Date date serialNumber | serialNumber > 0 = Just $ Date serialNumber | otherwise = Nothing
yes, I understand (Maybe seems the equivalent of c++'s boost::optional<T>).
-- smart constructor with day month year date2 day month year | month >= 1 && month <=12 = undefined | otherwise = error ("invalid month " ++ show month) To increase type safety it's a good idea to use as much explicit data types instead of Int values as possible:
data Month = January | ...
ok, I will try to change my code in that direction. The idea is clear.
I would use the descriptive names but leave out the 'date', because you could still have:
import qualified Date
Date.fromSerialNumber
also clear, yes. I think I have a better starting point now. Not impossible that I will come back later with further questions :-) Thank you for your help Peter