[Haskell] Re: Global Variables and IO initializers
Benjamin.Rudiak-Gould at cl.cam.ac.uk
Thu Nov 4 18:18:12 EST 2004
Benjamin Franksen wrote:
>On Thursday 04 November 2004 17:20, Ben Rudiak-Gould wrote:
>>This is one of the several ways in which the current implementation of
>>implicit parameters is broken. Clearly they *should* belong to the
>>module namespace, and if we modify the implementation so that they do,
>>the problem you describe here goes away.
>I have thought about this and I am not sure that this is possible or even
>makes sense. Remember that implicit parameters cannot be bound at the top
>level. They must be 'let' or 'where' bound.
Implicit parameter names (not bindings!) are public by their nature.
This is another way in which they're different from ordinary local
bindings. When you say "let x = ... in ...", there's no point putting x
in the module namespace because it's restricted to the current
expression by lexical scoping anyway. But with implicit parameters you
run into merging problems if a parameter like ?globals is used in two
different modules for different purposes, and both modules export a
function with ?globals in its type.
I don't think the issues here are any different that what we have to
deal with anyway with user-defined datatypes and type classes showing up
in exported types. If module Main imports module X, and X exports a
function with an implicit parameter ?p in its type, then ?p has to be in
X's namespace, or in the namespace of a module imported by X. Otherwise
X can't refer to it at all. It can't be in the Main namespace unless X
imports Main circularly. Export, import, and mention of implicit
parameters follow the same rules as other module-qualified identifiers.
But I just realized that it will probably be necessary to declare (not
bind!) implicit parameters at the top level to avoid capture problems.
(E.g. module X uses a parameter called ?p, but one day module Y,
imported unqualified by X, decides to add its own parameter ?p, and
suddenly X's ?p refers to ?Y.p instead of ?X.p.) This is unfortunate,
because it probably means adding a new keyword to the language.
More information about the Haskell