From: "gabriele renzi" <[EMAIL PROTECTED]>:
import structure MkRedBlackSet from "x-alice:/lib/data/MkRedBlackSet"
structure Set = MkRedBlackSet String
val set = Set.fromList mylist
The problem is that my list may contain duplicate words, and that would
cause an exception to be raised.
To avoid the excpetion I came up with this:
foldl (fn (item, set) => Set.insert (set, item)) (Set.empty) ws
Right. Or slightly shorter:
foldl (Fn.flip Set.insert) Set.empty ws
But it seems to me that inserting a list that may contain duplicates into
a set is quite a common operation, would it make sense to provide
this functionality as builtin, or is there some underlying rationale that
I
am missing?
The rationale is that the list is taken to be the extensional representation
of a set. As such it should not contain duplicates.
We particularly made that choice because we were burnt in the past by a
subtle bug where a list used to construct a set *unintenionally* contained
duplicates - which then were silently dropped, causing an error at far
places. So for the sake of stronger invariants, we chose to require the
programmer to make his intentions explicit if he *really* wants to allow
duplicates.
- Andreas
_______________________________________________
alice-users mailing list
[email protected]
http://www.ps.uni-sb.de/mailman/listinfo/alice-users