Num class

Marcin 'Qrczak' Kowalczyk mk167280@students.mimuw.edu.pl
Thu, 19 Oct 2000 10:28:37 +0200 (CEST)


On Thu, 19 Oct 2000, Tom Pledger wrote:

> If you had such a non-standard type, I imagine you'd also declare
> something like this:
> 
>     instance Subtype Int8  Int16 where ...
>     instance Subtype Int16 Int24 where ...
>     instance Subtype Int24 Int   where ...
> 
> and hence literals in the range -128 to 127 would be typed Int8, etc.

What would be the rule for typing integer literals? Currently it's
simple: fromIntegral (number::Integer), and Int8 is a completely
non-magical type.

With your proposal, assume that the programmer makes a bunch of subtype
declarations for his own types... What now?

(Assuming that subtyping can be reasonably embedded in the Haskell's type
system at all.)

A more concrete example. Does 10 have type Int8 or Word8? Is Int8 a
subtype of Word8, or the reverse? How could 10 be used as both Int8 and
Word8?

Current Haskell rules and not perfect: 12345::Int8 is legal. Conversions
are explicit and there is no distinction between always safe conversions
and those that may take an out of range parameter. But I'm happy with it;
conversions are rarely used anyway, rules are simple, and there is no
need of asking a question like: is every Int representable as Double
(the answer may depend on the implementation).

-- 
Marcin 'Qrczak' Kowalczyk