2
# let rec nth l n =
match l with
[] -> []
|h::t -> if n = 0 then h
else nth t (n-1);;
val nth : 'a list list -> int -> 'a list = <fun>
# let rec drop n l =
if n = 0 then l else
match l with
[] -> []
|h::t -> drop (n-1) t;;
val drop : int -> 'a list -> 'a list = <fun>
# let rec zipper a b =
match a with
[] -> b
|h::t -> h :: nth b 0 :: zipper t (drop 1 b);;
val zipper : 'a list list -> 'a list list -> 'a list list = <fun>
# zipper [1;3;5] [2;4;6];;
Characters 8-9:
zipper [1;3;5] [2;4;6];;
^
Error: This expression has type int but an expression was expected of type
'a list
두 목록을 결합하려고했습니다. 각 단계는 괜찮은 것처럼 보였지만 마지막 문장 인 지퍼 [1; 3; 5] [2; 4; 6]를 입력하면 오류가 나타납니다.Ocaml 오류에 대한 '목록 목록
'a in'유형을 학습 한 것은 Ocaml의 모든 유형 일 수 있습니다. 그렇다면, 표현식 타입 int는 괜찮 았습니다. 나는 무엇을 잘못 생각했는지 모른다.