To Tom Pledger's <[EMAIL PROTECTED]>
>> instance (Bounded a, Enum a) => Random a where ...
>>
>> But, every type in (Bounded, Enum) has a potential instance of Random,
>> using no properties of the type except its Bounded and Enum functions.
> [..]
Marcin 'Qrczak' Kowalczyk <[EMAIL PROTECTED]> writes
> Potential. But this does not need to be *the* implementation for
> all types (e.g. Doubles).
> So you want overlapping instances, with some rules of disambiguation?
> They cause troubles.
>
> E.g. the context (Bounded a, Enum a, Random a) could be reduced do
> (Bounded a, Enum a) (similarly as (Eq a, Eq [a]) can be reduced to
> Eq a), but then if such overloaded function is instantiated to Double,
> the wrong Random instance is chosen.
> And when different instances are visible in various modules, the same
> type can use different Random instances in those modules - without
> violation of the single instance rule. All instances themselves are
> legal, and the fact that one was not visible didn't cause compile
> time error in any module but is still a not so obvious error.
>
> GHC has a switch -fallow-overlapping-instances. But they are not
> very safe.
To my mind, even such instance overlaps should be possible as, say
class C a where c :: a -> a -> a
instance Ord a => C a where c = min
instance (Ord a, Num a) => C a where c = otherWay
This is proposed in
http://www.haskell.org/docon/2/ ... manual, section {lne}.
This is because the mathematics needs it.
On the other hand, one has to think further on what kind of strange
effects this may cause.
My DoCon-2 program exploits -optC-fallow-overlapping-instances
-optC-fallow-undecidable-instances
of GHC and still complains on the language being too restrictive.
Indeed, I had met a couple of times in practice that forgetting of
import <CertainModule> ...
may lead to successful compilation and the un-desired change of
computation result at the run-time!
After some ad hoc fix in `import' this effect disappeared, but the
shock was terrible. I guessed why this happened and am wondering
when it would shoot again.
Probably, one has to invent some systematic approach to prevent
forgetting of `import' of instances to overlap.
Maybe, some utility has to scan all the project for this (not only
the imported modules), and help to recall where the overlaps reside
?
Maybe, some style or discipline has to be invented for this.
------------------
Sergey Mechveliani
[EMAIL PROTECTED]