'Convertible' class?
Dylan Thurston
dpt@math.harvard.edu
Wed, 7 Feb 2001 15:43:59 -0500
In thinking about various issues with the numeric classes, I came up
with the following question: Is there a problem with having a class
'Convertible' as follows?
class Convertible a b where
convert :: a -> b
So, e.g., fromInteger and fromRational could be replaced with
convert. (But if you did the same thing with toInteger and toRational
as well, you run into problems of overlapping instances. I think
there are good semantic reasons for this: fromInteger and fromRational
can be defined in terms of the basic +,*,zero,one, while toInteger and
toRational rely on details of the representation.)
What do people think of this idea in general? Perhaps a better name
would be 'Subtype'?
Note that "convert . convert" would be up there with "show . read" as
an ambiguous term.
Best,
Dylan Thurston