[Haskell-beginners] type class for custom numeric types

Ashish Agarwal agarwal1975 at gmail.com
Thu Apr 8 22:42:48 EDT 2010


I'd like to define an abstract type T, and some how make the following work:

> 3 :: T
-- allow integer literals to be read as values of type T

> 100 :: T
error: value out of bounds for type T
-- place some restrictions on which integers are valid T values

To get the first feature, is my only option to make T an instance of the Num
class? If so, I'd have to make fromIntegral return error for out of bounds
values. Is there any problem in doing that? The only law I find mentioned
for instances of Num is: abs x * signum x == x. Is this the complete
requirement?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100408/285d69cd/attachment.html


More information about the Beginners mailing list