私はOCamlが初めてで、いくつかの基本的な関数を書こうとしています。
find_new
関数 (この関数は基本的に、最初のリストにのみ表示される要素のリストを見つけることです) を使用curry2
して定義すると機能しないことがわかりました。
let curry2 f (x,y) = f x y
let flip f x y = f y x
let compose f g x = g (f x)
let rec elem v xs = match xs with
[] -> false
| (h::t) -> if v = h then true else elem v t
let rec filter fb l = match l with
[] -> []
| (h::t) -> if fb h
then h::(filter fb t)
else (filter fb t)
let x = [5;6;7;3] ;;
let y = [5;6;7;5] ;;
let z = [7;5;6;5] ;;
let a = [3;5;8;9] ;;
let find_new_ xs ys = filter (compose ((flip elem) ys) not) xs ;;
let find_new (xs,ys) = find_new_ xs ys;; (* works *)
(* let find_new = curry2 find_new_;; *) (* doesn't work *)
find_new (x,[3]);;
find_new (x,[3;5]);;
find_new (x,[3;6]);;
find_new ([x;y;z],[y]);;
find_new ([x;y;z],[y;x]);;
find_new
(コメントアウトされた)の2番目の定義を使用すると、エラー情報は次のようになりました。
Error: This expression has type int list
but an expression was expected of type int
だから、私のコードの何が問題なのだろうか?