Ocamlプロジェクトに、重複しない別のリストにリストを追加するのに役立つヘルプ機能があります。例えば 、list y [a, b, c, d]
にlist x: [d, e, f, g]
を追加し、結果があるべきである[A、B、C、D、E、F、G]Ocamlリストを重複なしで別のリストに追加する
Iが書いた関数は次のようである:
(* helper function checks if list contains element *)
let rec find e l =
match l with
[] -> false
|(h::t) -> if (h = e) then true else find e t
;;
(* helper function append l1 to l2 without duplicate *)
let rec help_append_list l1 l2 =
match l1 with
[] -> l2
|(h::t) -> if (find h l2 = false) then (help_append_list t ([h]@l2)) else (help_append_list t l2)
;;
しかしdosen」私はそれを使用するときにうまく動作するように見える、それはまだ重複する要素が表示されることが判明。
あなたがSet
を使用する場合は、あなただけのために2セットの結合を必要とする)=
ありがとう...