Skip to content

Commit ced6099

Browse files
committed
Dates in month, return a list of the dates
1 parent cacfbf9 commit ced6099

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Making functions private
2+
3+
You do it by declaring the function in the let part of the function that will use it!
4+
5+
Where can you use a local function f1 defined inside another function?
6+
7+
In later bindings of the let expression or the body of the let expression.
8+
9+
In the countup_from function he showed, he stuck the count function inside of it and then removed the redundant variable for "to", since the "x" in the outer function would be the same as it.
10+
11+
## When to use nested functions?
12+
13+
Use 'em when you want them to be private! If they're likely to be misused or changed.
14+

Week-2-Intro-to-SML/assignment1KL.sml

+9
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,12 @@ fun number_in_months (dates: (int*int*int) list, months: int list) =
2424
then 0
2525
else number_in_month(dates, hd months) + number_in_months(dates, tl months)
2626

27+
fun dates_in_month (dates: (int*int*int) list, month: int) =
28+
if null dates
29+
then []
30+
else if (#2(hd(dates))) = month
31+
then hd(dates) :: dates_in_month(tl dates, month)
32+
else dates_in_month(tl dates, month)
33+
34+
35+

0 commit comments

Comments
 (0)