Created
May 26, 2018 08:51
-
-
Save fdjones/55d783304c255fb6e3c5fa09de2ba1d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* functions *) | |
fun number_before_reaching_sum (sum : int, xs : int list) = | |
let fun sum_aux (limit, ys, acc, count) = | |
if acc >= limit | |
then count - 1 | |
else | |
sum_aux (limit, tl ys, acc + hd ys, count + 1); | |
in | |
sum_aux(sum, xs, 0, 0) | |
end | |
fun what_month (day : int) = | |
let val months = [31,28,31,30,31,30,31,31,30,31,30,31] | |
in | |
1 + number_before_reaching_sum (day, months) | |
end | |
fun month_range (day1 : int, day2 : int) = | |
if day1 > day2 then [] | |
else | |
let | |
fun what_month (day : int) = | |
if day > day2 then 0 | |
else | |
let val months = [31,28,31,30,31,30,31,31,30,31,30,31] | |
in | |
1 + number_before_reaching_sum (day, months) | |
end; | |
in | |
what_month (day1) :: what_month (day1 + 1) | |
end | |
(* tests and error message *) | |
val number_before_reaching_sum = fn : int * int list -> int | |
val what_month = fn : int -> int | |
homework-week-1.sml:93.6-93.48 Error: operator and operand don't agree [tycon mismatch] | |
operator domain: int * int list | |
operand: int * int | |
in expression: | |
what_month day1 :: what_month (day1 + 1) | |
val it = () : unit | |
homework-week1-test.sml:22.14-22.25 Error: unbound variable or constructor: month_range | |
val it = () : unit | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment