3 ms·
The point of the article is that it doesn't have to fail gracefully. Consider the API: data Date = Date { getYear :: Int, getMonth :: Int, getDay :: Int }
by crdrost 5y ago
The point of the article is that it doesn't have to fail gracefully.
Consider the API:
data Date = Date { getYear :: Int, getMonth :: Int, getDay :: Int }
deriving (Eq, Ord, Show)
addDays :: Date -> Int -> Date
addMonthsRounded :: Date -> Int -> Date
Someone who does
d `addMonthsRounded` 3
immediately has a contextual clue that there might be something fishy going on, and has a string they can google to get to the docs to find out that this "Rounded" business is all about "hey, the code
let y = (x `addMonthsRounded` 1) `addMonthsRounded` (-1)
in y == x
might sometimes return False because it truncates if your day doesn't fit in the given month."