KEMBAR78
SML Calendar Assignment | PDF
0% found this document useful (0 votes)
24 views2 pages

SML Calendar Assignment

The document outlines a calendar assignment involving the implementation of various Standard ML functions related to date manipulation, such as checking if one date is older than another and converting dates to strings. It includes a list of implemented functions, sample test cases, and a reflection on the learning experience. The author declares the work as their own and compliant with course policies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

SML Calendar Assignment

The document outlines a calendar assignment involving the implementation of various Standard ML functions related to date manipulation, such as checking if one date is older than another and converting dates to strings. It includes a list of implemented functions, sample test cases, and a reflection on the learning experience. The author declares the work as their own and compliant with course policies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Calendar Assignment - SML Functions

Implemented Functions

1. is_older : (int * int * int) * (int * int * int) -> bool


fun is_older ((y1, m1, d1), (y2, m2, d2)) =
y1 < y2 orelse (y1 = y2 andalso m1 < m2) orelse (y1 = y2 andalso m1 = m2 andalso d1
< d2)

2. number_in_month : (int * int * int) list * int -> int


<recursive implementation>

3. number_in_months : (int * int * int) list * int list -> int


<recursive implementation using number_in_month>

4. dates_in_month : (int * int * int) list * int -> (int * int * int) list
<filtering implementation>

5. dates_in_months : (int * int * int) list * int list -> (int * int * int) list
<uses dates_in_month and append (@)>

6. get_nth : string list * int -> string


fun get_nth (lst, n) =
if n = 1 then hd lst else get_nth(tl lst, n - 1)

7. date_to_string : int * int * int -> string


val month_names = ["January", "February", ..., "December"]
fun date_to_string (y, m, d) =
get_nth(month_names, m) ^ " " ^ Int.toString d ^ ", " ^ Int.toString y

8. number_before_reaching_sum : int * int list -> int


<recursive implementation>

9. what_month : int -> int


val days_in_month = [31,28,31,30,...]
fun what_month (doy) =
1 + number_before_reaching_sum(doy, days_in_month)

10. month_range : int * int -> int list


<generates months between two days using what_month>

11. oldest : (int * int * int) list -> (int * int * int) option
<returns oldest using is_older recursively>
Sample Test Cases (in calendar_test.sml)

is_older((2020, 5, 1), (2021, 1, 1)) (* true *)


number_in_month([(2020, 1, 10), (2020, 1, 20)], 1) (* 2 *)
get_nth(["a", "b", "c"], 2) (* "b" *)
date_to_string(2021, 12, 25) (* "December 25, 2021" *)
what_month(60) (* 3 *)

Reflection

This assignment helped me practice working with tuples, lists, recursion, and string formatting in
Standard ML. The task encouraged modular design by building new functions using previously
defined ones.

Declaration

I declare that this assignment is my own work and has been completed following the course policies.

Signature: ___________________
Date: ___________________

You might also like