OCaml で Bag
google:OCaml で Bag で検索したら「もしかして: ocamldebug 」とか言われるかと思いましたが, Google はそこまで賢くありませんでした. というくだらない話はさておき, OCaml で Bag のようなデータ構造 (同一要素が区別される集合) が必要になったので作ってみました. 作ったといっても Set モジュールを使っただけの単純なものです.
# module StringBag = Set.Make(struct type t = string let compare x y = max_int lor compare x y end);; module StringBag : sig type elt = string (* 略 *) end # StringBag.elements (StringBag.add "to" (StringBag.add "die" (StringBag.add "or" (StringBag.add "not" (StringBag.add "to" (StringBag.add "die" StringBag.empty))))));; - : StringBag.elt list = ["die"; "die"; "not"; "or"; "to"; "to"]大きな Bag を想定していないなら単に List を使えばいいと思います.