나는 일년의 이틀을 입력으로 받아들이는 함수 (예 : 65와 128, 연도가 365 일이라고 가정)를 가지고 day1에서 day2까지의 날이 속한 월의 수를 가진 목록을 반환하는 month_range
함수가있다. .일년의 이틀을 제공하여 월 목록을 얻는 방법?
목록의 크기는 "day2 - day1 + 1"이어야합니다.
예 : month_range (25, 35)를 반환해야합니다 : [1,1,1,1,1,1,1,2,2,2,2]
나는 다음과 같은 코드를 작성fun month_range (day1:int,day2:int) =
let
val month_days= [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
fun what_month(day :int) =
let
fun aux(sum :int, numbers: int list) =
let
val numbers_tail = tl numbers
in
if sum <= (hd numbers)
then 1
else
1 + aux(sum, (hd numbers + hd numbers_tail)
:: (tl numbers_tail))
end
in
aux(day, month_days)
end
in
if (day1>day2)
then []
else what_month(day1) @ what_month(day1 + 1)@::what_month(day2)
end
하지만 정말 이해가되지 않는, @::
를 사용하고 있는지, 나에게 오류 메시지에서 볼 수있는 다음과 같은 오류
/tmp/emacs-region5156f3r:21.51-21.54 Error: unbound variable or constructor: @::
/tmp/emacs-region5156f3r:21.12-21.70 Error: operator is not a function [literal]
operator: int
in expression:
(what_month (day1 + 1)) <errorvar>
/tmp/emacs-region5156f3r:21.12-21.70 Error: operator and operand don't agree [literal]
operator domain: 'Z list * 'Z list
operand: int * _
in expression:
what_month day1 @ (((what_month <exp>) <errorvar>) what_month) day2
uncaught exception Error
raised at: ../compiler/TopLevel/interact/evalloop.sml:66.19-66.27
../compiler/TopLevel/interact/evalloop.sml:44.55
../compiler/TopLevel/interact/evalloop.sml:296.17-296.20
추가 할 때 코드를 형식화하고 항상 오류 메시지도 넣으십시오. –
OK, Jes ... 내가 할께. – Olivia