3
sum이라는 int를 취하는 함수 number_before_reaching_sum
을 작성하고 목록의 첫 번째 n 요소가 sum보다 작게 추가되도록 int n을 반환하지만 목록의 첫 번째 n + 1 요소가 sum 이상을 추가합니다. 여기에 오류 메시지가 출력합니다 내 코드표준 ML 오류 : 연산자와 피연산자가 일치하지 않음
fun number_before_reaching_sum(sum:int,lists:int list)=
let
val sum_list=0
val n=0
in
let fun list_compute(sum_list:int,lists2:int list,n:int)=
let val sum_list2=sum_list+(hd lists2)
in if sum_list2>=sum
then (sum_list2,n+1)
else (#1 list_compute(sum_list2,tl lists2,n+1),#2 list_compute(sum_list2,tl lists2,n+1))
end
in #2 list_compute(sum_list,lists,n)
end
end
입니다 : (#1 list_compute(sum_list2,tl lists2,n+1),#2 list_compute(sum_list2,tl lists2,n+1))
및 #2 list_compute(sum_list,lists,n)
이 2 개 라인이 잘못된 이유
hw1_1.sml:67.14-67.97 Error: operator and operand don't agree [type mismatch]
operator domain: {1:'Y; 'Z}
operand: int * int list * int -> 'X
in expression:
(fn {1=1,...} => 1) list_compute
hw1_1.sml:67.14-67.97 Error: operator and operand don't agree [type mismatch]
operator domain: {2:'Y; 'Z}
operand: int * int list * int -> 'X
in expression:
(fn {2=2,...} => 2) list_compute
hw1_1.sml:69.11-69.44 Error: operator and operand don't agree [type mismatch]
operator domain: {2:'Y; 'Z}
operand: int * int list * int -> int * int
in expression:
(fn {2=2,...} => 2) list_compute
내가 알아낼 수 없습니다.
일반적으로 표준 ML에서 이와 같은 오류가 발생하면 괄호 안의 일부 표현식을 감싸는 것을 잊었 기 때문입니다. –