
Designers of FiniteMap and Set (it's me again), I wish "keysFM" would yield "Set key" rather than "[key]"! Could such an implementation take constant time (by simply ignoring "elts")? (Converting a list to a set and back will sort the list and thus may take more than linear time.) Cheers Christian

Designers of FiniteMap and Set (it's me again),
I wish "keysFM" would yield "Set key" rather than "[key]"!
Could such an implementation take constant time (by simply ignoring "elts")?
IIRC a Set key is simply a FiniteMap key key. So what you require is simply a mapFM (\k v -> k). Correct me if I'm wrong... --KW 8-)

Keith Wansbrough wrote:
I wish "keysFM" would yield "Set key" rather than "[key]"!
IIRC a Set key is simply a FiniteMap key key. So what you require is simply a mapFM (\k v -> k).
Set is an abstract data type , that can be viewed as a sorted list without duplicates (or as a special mapp, see below). Simply in order to document that property "keysFM" should return "Set key"! You're suggestion "mapFM (\k v -> k)" yields a "FiniteMap key key". The internal representation, however, is (by mere coincidence) "FiniteMap key ()", so "mapFM (\k v -> ())" would be a correct implementation, but only if I knew the internal representation of a set and could use the hidden constructor for Set.
Correct me if I'm wrong...
I hope I did, Cheers Christian
participants (2)
-
Christian Maeder
-
Keith Wansbrough