From: Nicolas C. <war...@fr...> - 2005-06-06 05:54:18
|
> > > Hello, > > > > > > Some useful operations over the keys of a map are not provided by the > > > standard Map module, neither by ExtLib's PMap, but are provided only by > > > the Set module. > > > > Yes I would also love to set diff / union / intersection for PMaps. > > But I'm not sure which semantic is appropriate. > > Maybe only have diff / union / inter operations on *keys* would be enough ? > > Please fell free to post implementation, maybe based on Set module. > > What do you think of this: > > (* default merge = fun x y -> x *) > val union : ?merge:('b -> 'b -> 'b) -> ('a, 'b) t -> ('a, 'b) t -> ('a, 'b) t > > (* a merge function must be given to inter *) > val inter : merge:('b -> 'c -> 'd) -> ('a, 'b) t -> ('a, 'c) t -> ('a, 'd) t > > val diff : ('a, 'b) t -> ('a, 'c) t -> ('a, 'b) t Why not generalize a little more ? val union : merge:('b -> 'c -> 'd) -> ('a,'b) t -> ('a,'c) t -> ('a,'d) t The only problem is that we can't use "identity" as default merger. Nicolas |