"Ch. A. Herrmann" wrote:
> I had just a fast look at the following I found at the
> page "http://www.cse.ogi.edu/PacSoft/projects/Hugs/hugsman/exts.html"
> for dynamic scoping:
>
> min :: [a] -> a
> min = least with ?cmp = (<=)
>
> Actually, I'm not sure how referential transparency can be established
> with these implicit parameters. Assume min to be called at two places
> with a different value for cmp, but with the same input list. Or is it
> the case that the type a is bound to a particular cmp all over the program?
>
> Please note, that referential transparency is one main advantage Haskell
> has in contrast to other languages .....
A paper on implicit parameters will appear in POPL'00 that will answer this
sort of question. I'll post a reference to it later when I get a chance to
put it on my web page.
But in short, for `min' to be called in two places, within the same lexical
scope, with different bindings for `?cmp' implies that there's an intervening
`with' binding in that same lexical scope. To avoid the problem you allude
to, we extended substitution, particularly thru `with' bindings, to preserve
dynaming scoping (i.e. to prevent dynamic capture). Thus referential
transparency is retained, you just have to be careful when you substitute -
just as you have to be careful with regular static name capture.
--Jeff