It is said, next  ghc  is going to support the included overlapping
instances.
At this point, i have a question to the Haskell experts and 
implementors, concerning the duplicate definitions.
For example, program the determinant of a matrix:
---------------------------------------------------------------------
class Num a => Field a where  divide :: a -> a -> a

data Matrix a = Mt [[a]] 

det :: Num a => Matrix a -> a
det             (Mt rs)  =  expandByRow rs
                            where
                            expandByRow rs =  ...something with +,-,*

det :: Field a => Matrix a -> a
det               (Mt rs)  =  gaussMethod rs
                       where
                       gaussMethod rs = ...something with +,-,*,divide
----------------------------------------------------------------------
For the case of   det m,   m :: Field a => Matrix a,
the compiler has to set the second definition of  det.  For under this
stronger condition, the better algorithm is possible - gaussMethod.
Otherwise, the compiler has to choose the first definition - at least,
it yields the correct result.
At this, Haskell reports an error: duplicated definitions for  det.

Providing the two functions, say,  det, det_f  for the user to choose 
is an ugly way out: the mathematical map is the same, why call it 
different? In other words, the values in the language are not 
polymorphic enough.
So, try to help this by using  ghc with  -fallow-overlapping-instances
and by making `det' a class method:
----------------------------------------------------------------------
class WithDet a  where  det :: Matrix a -> a
                        
instance Num a   => WithDet a  where  det (Mt rs) = expandByRow ...
instance Field a => WithDet a  where ...            gaussMethod ...
----------------------------------------------------------------------

will        ghc -c -fglasgow-exts -fallow-overlapping-instances
allow this?
If it will, then could the compiler resolve in the "similar" way the 
duplicated  det  definitions in the first program - and thus provide 
the corresponding language extension?


------------------
Sergey Mechveliani
[EMAIL PROTECTED]
http://www.botik.ru/~mechvel

Reply via email to