Scope of imported names
Marcin 'Qrczak' Kowalczyk
Fri, 2 Nov 2001 23:08:00 +0000 (UTC)
Fri, 2 Nov 2001 09:30:37 -0800, Simon Peyton-Jones <email@example.com> pisze:
> | They are also different in spirit from the rules for
> | instance declarations in section 4.3.2 where the binding
> | occurrences for the names of the methods must be qualified if
> | the unqualified method name is not in scope.
> I will therefore propose the following simplification:
> remove the stuff from 4.3.2 about having a qualified name
> for the class method; after all, an instance declaration is
> only *allowed* to have declarations for the class methods
> That would simplify the syntax, and make the language more consistent.
> Any objections?
I don't have a strong opinion in either way, ok for me to make this
change, but I don't agree that it would be more consistent. Instances
don't contain binding occurrences of method names!
They are not exported from the module which contains the instance.
Well, instances are exported semantically, but not names of methods.
You can't have a fixity declaration there. You can't have a type
signature, although it's sometimes written in a comment (perhaps it
should be permitted?).
It's true that it's unambiguous because of the class they are written
in. And they syntactically looks like binding occurrences to create
an illusion that it's overloading... But in fact they contribute code
to the same function which happens to dispatch the implementation on
the type it is used at. At least this is how I think about it.
I've recently implemented a toy language where providing implementations
of generic functions is done by executing a particular function, giving
it three arguments: the generic function, the type, and the implementation.
It's clearly not a binding occurrence - the function must have already
existed before. Similarly in Haskell.
__("< Marcin Kowalczyk * firstname.lastname@example.org http://qrczak.ids.net.pl/