For many functions that operate on lists (such as map, foldr, etc.) one or more strategies that will be applied more than once have to be passed as arguments. One option is to give a name to the strategy that is passed to such functions, and then correct scoping of variables is achieved automatically. If, however, the strategy is specified “inline”, then scoping has to be done manually. If all the variables used in the strategy have to be scoped, then { s } can be used. But many times (at least in my experience) all variables except one or two have to be scoped. Then, { s } cannot be used anymore, since that will scope the one or two variables that don’t have to be scoped as well, which obviously goes wrong. The only solution, then, is to list all the variables that have to be scoped explicitly, like { a, b, c, d, e, f : s }. Sometimes, especially if s is quite involved, it can be that the programmer misses one or two variables that have to be scoped, and then the application of map or foldr or whatever fails. It would be nice, then, to have syntax for saying “scope all the variables in this strategy except a listed few”. Then, instead of saying { a, b, c, d, e, f : s } and risking to forget one or two variables, one would say { -x : s } to specify that x is the only variable in s that shouldn’t be scoped.

Motivation:

1) In my experience, it is often the case that the number of variables that need to be scoped exceeds by far then one of variables that don’t, so having such a construct would save some typing.

2) With the new construct, if the programmer forgets to “de-scope” a variable which she uses in s, the compiler will most of the times signal an error that: “variable … is used but not bound”, which further helps with avoiding mistakes.

Submitted on 3 March 2006 at 15:03

On 9 January 2013 at 16:58 Eelco Visser removed tag 0.18M5

On 9 January 2013 at 16:58 Eelco Visser tagged 0.19M1

On 9 January 2013 at 17:03 Eelco Visser removed tag 0.19M1

On 9 January 2013 at 17:03 Eelco Visser tagged interesting

Log in to post comments