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
S.D.Mechveliani (mechvel@math.botik.ru) wrote: [snip] : 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 I just want to add that this is almost similar to a mechanism I've implemented. You really need this. Regards, Marc van Dongen
Thu, 08 Feb 2001 09:41:55 +0300, S.D.Mechveliani <mechvel@math.botik.ru> pisze:
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.
Defining a domain by a sample argument is neither elegant (most of the time it's not needed because the type determines the domain) nor general (when considering domains not defined by types, there can be more than one domain sharing a value of the carrier type). So this is generally a bad idea. -- __("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ SYGNATURA ZASTÊPCZA QRCZAK
Hello! On Fri, Feb 09, 2001 at 02:59:53AM +0000, Marcin 'Qrczak' Kowalczyk wrote:
[...]
Defining a domain by a sample argument is neither elegant (most of the time it's not needed because the type determines the domain) nor general (when considering domains not defined by types, there can be more than one domain sharing a value of the carrier type). So this is generally a bad idea.
Agree. And if an explicit type is needed, you can still use type declarations. And if you need the type from a sample value, you can use `asTypeOf` (where asTypeOf :: a -> a -> a; foo `asTypeOf` bar = foo). Kind regards, Hannah.
participants (4)
-
Hannah Schroeter -
Marc van Dongen -
qrczak@knm.org.pl -
S.D.Mechveliani