[Haskell-cafe] Re: Positive integers
Aaron Denney
wnoise at ofb.net
Sun Mar 26 22:22:25 EST 2006
On 2006-03-26, Daniel McAllansmith <dagda at xtra.co.nz> wrote:
> I was thinking about several things in this thread, torsors, overflow
> semantics, bounds checking...
> I wonder if there would be any merit in being able to define constrained
> subsets of integers and the semantics when/if they overflow.
>
> For example, take UNIX nice levels -20 to 19. You could have
> data ConstrainedInteger = CI {distToMax :: Natural, distToMin :: Natural}
> this would ensure only the 40 integers can be represented.
> Then you could have _something_ that defined what happened on overflow,
> whether it wraps, reflects, errors, truncates or whatever.
>
> When it comes to compile, or source preprocessing, time these numbers
> could be realigned to a primitive Int or Word representation of
> suitable size and have the appropriate overflow code written in. And,
> in the case of error or wrap overflow semantics on a set of the right
> size, the overflow checks could be disabled, like other assertions, at
> runtime.
Now that is an interesting idea.
--
Aaron Denney
-><-
More information about the Haskell-Cafe
mailing list