[m-dev.] Foreign type compare and unification
Peter Schachte
schachte at cs.mu.OZ.AU
Wed May 22 12:59:13 AEST 2002
> What I'm saying is that the behaviour of the program should not depend on
> a closed world assumption about the members of a typeclass.
Why not? No, really.
I think it makes sense for me to be able to indicate that a type
belongs in a type class (and define its methods) when I declare the
type. It also makes sense for me to be able to specify that a type
belongs in a class (and define its methods) when I want to use that
type. But when someone else using that type in another way in another
part of the code declares that type to be in a class (and define its
methods), it does not make sense that this should have any effect on
my code. This defies the principle of locality of effects. I gather
this flaw is inherited from Haskell, and perhaps it is too late to do
anything about it. But if I understand the issue you are raising
correctly, it's only an issue because of this flaw.
My conjecture is that if I could define an equavalence type, but the
old type's class memberships did not flow automatically to the new
one, and if I could cast a term between these types, this could
provide a work around for the problem. Not ideal, but perhaps good
enough. So if someone else declares string to be in the comparable
class using ordinary comparison, I could define
case_insensitive_string to be an alias for string, but I could declare
it to be an instance of comparable using case insensitive comparison.
Then when I get strings that I want to be treated case insensitively,
I cast them to case_insensitive_string before doing anything else
with them. When I want to pass a case_insensitive_string to some
ordinary string operation, I'd cast it back to string. Perhaps
Mercury could perform coersion in such cases; I don't think that would
present problems.
This isn't a complete solution because the effects of a class
declaration are still not local, it's just that there is a work
around. Also, if some large polymorphic term is already constructed
with strings in it, I don't have a way to change all those strings to
case_insensitive_strings in one go. And if the type of the term is
monomorphic, where parts are declared to be of type string, there's no
way I can do to put in case_insensitive_strings.
--
Peter Schachte A nation that continues year after year to spend
schachte at cs.mu.OZ.AU more money on military defense than on programs
www.cs.mu.oz.au/~schachte/ of social uplift is approaching spiritual doom.
Phone: +61 3 8344 9166 -- Martin Luther King, Jr.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list