Added exercises 2.2, 2.3, 2.4, and 2.5

This commit is contained in:
j4nk 2025-02-12 00:28:40 -05:00
commit 70450a3f99
5 changed files with 32 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*~
#*

1
02.02/answer.txt Normal file
View File

@ -0,0 +1 @@
I agree that it would be nice if we just had numbers but the implementation would be tough as when real numbers get very close to ints, it is not clear at what point you can switch to integer operations over FP operations on the backend.

3
02.03/answer.txt Normal file
View File

@ -0,0 +1,3 @@
The first function requires type constraint because n could be an integer or a real
The second function does not require type constraint because Math.sin takes a real to a real, meaning that the compiler would be able to infer that this function takes a real to a real
The third function requires type constraint because k could be an integer or a real

3
02.04/answer.txt Normal file
View File

@ -0,0 +1,3 @@
For the first version of digit, an argument of ~1 would return the character corresponding to the character code before the character code for "0" and an argument of 10 would return the character code 10 character codes after "0"
For the second version of digit, they would cause errors

23
02.05/date.sml Normal file
View File

@ -0,0 +1,23 @@
fun valid_date (d:int, m:string) = if (m="January" orelse
m="March" orelse
m="May" orelse
m="July" orelse
m="August" orelse
m="October" orelse
m="December") andalso
d <= 31 andalso
d >= 0 then
true
else if (m="April" orelse
m="June" orelse
m="September" orelse
m="November") andalso
d <= 30 andalso
d >= 0 then
true
else if m="February" andalso
d <= 28 andalso
d >= 0
then
true
else false