[Hat] Thoughts, Int vs Integer

Neil Mitchell ndmitchell at gmail.com
Sat Jun 24 15:41:47 EDT 2006


Hi,

Often when compiling with Hat I run into the Int vs Integer issue, in
fact this is pretty much the biggest problem I have getting hat traces
generated. I was considering if there was any possible change that
could be performed by Hat to remove this restriction.

The best I came up with makes semantic changes to the program, but
these changes are "very minimal" at a guess :)

The idea basically revolves around "type Int = Integer" - replace all
occurances of Int with Integer at the type level, make all functions
that operate on Int now operate on Integer instead, and all numeric
literals can now become Integer, since there is no Int.

There are two semantic changes from this which I have thought of:

1) big_number * 2 will never overflow, which will give a different
semantics. Personally this sounds like a good idea, and having a
hat-overflow tool to detect when an Integer goes above 2^31 would
probably be a useful addition. I don't consider this change to be all
that bad, since its compatible with the Haskell98 report (I think).

2) More seriously, type classes will lead to different code being
invoked. For example while 0 == 0 might have invoked Int equality now
it will invoke Integer equality. My guess is that if there is a
program where the type class for Int is not a subset of the behaviour
of that for Integer, its very weird and confusing and probably buggy.

The changes to the generator that would need to be made are (as far as
I can tell) as follows:

* Replace all occurances of Int with Integer
* Make all numeric literals 0 :: Integer
* On encountering a typeclass if there existing an instance for one of
Int or Integer, then use that one. If instances exists for both Int
and Integer then throw away the Int version. For a prototype,
allow-undecideable-instances & allow-overlapping-instances should
handle this automatically.
* Any primitive operations that are performed on Int and not Integer
would need to be worked around, probably on a case by case basis, but
this should be a small number.

Comments or thoughts?

Thanks

Neil


More information about the Hat mailing list