I found the following text when visiting the Clean (a functional language) site: "Clean is the only functional language in the world which has a special type system, uniqueness typing. It enables to update function arguments destructively retaining the purity of the language." Then I have some questions: 1. Can anyone explain what does "update function arguments destructively" mean? 2. If this is a desirable thing, why does Haskell not implement it? Thanks, -- Andre
Andre W B Furtado wrote:
I found the following text when visiting the Clean (a functional language) site:
"Clean is the only functional language in the world which has a special type system, uniqueness typing. It enables to update function arguments destructively retaining the purity of the language."
I believe Mercury borrowed their uniqueness type (mode) system from Clean. But since Mercury is functional/logical then I guess its still true that Clean is the only functional language with a uniqueness type system.
Then I have some questions: 1. Can anyone explain what does "update function arguments destructively" mean?
Uniquely typed values are guaranteed to be referenced at most once under program evaluation, these values can be modified in-place. As an example, suppose I have an array and I want to modify an element. In general I need to create a whole new copy of the array in order to make the modification since there may be other places in the program that require access to the old array. However, if I know that the old array has no other references (because the array has a unique type) then I do not need to make a copy, I can just modify the original array. This has obvious efficiency benefits.
2. If this is a desirable thing, why does Haskell not implement it?
- Uniqueness types, of course, require replacing the type system, this is a non-trivial task, - Destructive updates can already be accomplished with compiler supported libraries using monads, - Uniqueness types invalidate some program transformations. On the other hand I think uniqueness types are quite useful. Particularly as they allow much more flexible interaction between mutable data-structures than monadic approaches. I don't know of any concrete reasons a uniqueness type system couldn't be added to Haskell. This seems like a fine time to insert a plug for my Master's thesis, which describes a denotational semantics of uniqueness types: http://www.cpsc.ucalgary.ca/~danaha/uniqueness-types.ps Dana
On 12-Mar-2002, Dana Harrington <dgharrin@ucalgary.ca> wrote:
I believe Mercury borrowed their uniqueness type (mode) system from Clean.
Nope. The support for unique modes in Mercury was developed before we were aware of Clean. They achieve similar aims, but it's a case of convergent evolution, because we were both trying to solve the same problem, rather than borrowing. (This is in contrast to e.g. Mercury's support for type classes, which was pretty much directly lifted from Haskell.) In fact Clean's support for uniqueness is better than Mercury's. In particular, Clean supports uniqueness polymorphism, whereas Mercury only supports overloading on uniqueness. -- Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit The University of Melbourne | of excellence is a lethal habit" WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
participants (3)
-
Andre W B Furtado -
Dana Harrington -
Fergus Henderson