[Haskell-beginners] Further constraining types

Christopher Howard christopher.howard at frigidcode.com
Fri Aug 5 16:56:38 CEST 2011

On 08/05/2011 02:50 AM, Daniel Fischer wrote:
> 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.)

*my head explodes*

Guess I'll have to use Integers from now on.


More information about the Beginners mailing list