
5 Aug
2011
5 Aug
'11
6:50 a.m.
On Friday 05 August 2011, 04:52:03, Christopher Howard wrote:
But this means the type of square would have to be changed to
square :: Int -> Maybe (Positive Int)
...which is unacceptable. (I know square will always return an positive integer, not that it might do so!)
As for Int, that's not true: Prelude> 4000000000^2 :: Int -2446744073709551616 The square of an Integer will be nonnegative (or kill your process by OOM), but to decide whether something could return a (Positive Foo) instead of a (Maybe (Positive Foo)), you have to take Foo's semantics into account in addition to the abstract mathematical properties of the algorithm. (Tangential to your point, but nevertheless.)