`Covertible' class. Reply.
S.D.Mechveliani
mechvel@math.botik.ru
Thu, 08 Feb 2001 09:41:55 +0300
Dylan Thurston <dpt@math.harvard.edu> writes
> 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
>
> [..]
The basic algebra library BAL
http://www.botik.ru/pub/local/Mechveliani/basAlgPropos/bal-pre-0.01/
suggests class Cast a b where cast :: a -> b -> a
If s is an element of a certain domain, then one can use the
construction
cast s x
to convert various data x to corresponding canonical values in the
domain defined by s. For example, if s <- Z[x]
is a polynomial over Integer, then the expressions
cast s 2, cast s (2,3)
give the constant 2, considered as a polynomial, and a one-term
polynomial equal to 2*x^3.
Also BAL overloades +, * ... by hiding-reexporting the standard
Prelude and implements the algebraic categories Group, Ring ...
-----------------
Serge Mechveliani
mechvel@botik.ru