diff --git a/src/ica04/ica4.sml b/src/ica04/ica4.sml index d1b30c5..05d50af 100644 --- a/src/ica04/ica4.sml +++ b/src/ica04/ica4.sml @@ -11,12 +11,19 @@ fun cubeR(a: real) = a * a * a; fun combine((i1, i2), (i3, r1), (r2, i4), (r3, r4)) = real(i1 + i2) * (real(i3) + r1) * (r2 + real(i4)) * (r3 + r4); (* Question 5 *) +(* Bad Version (not using pattern matching) *) fun firstChars(a, b) = if (a = "" andalso b = "") then "" else if a = "" then implode([hd(explode(b))]) else if b = "" then implode([hd(explode(a))]) else implode([hd(explode(a))] @ [hd(explode(b))]); +(* Good Version (using pattern matching) *) +fun firstChars("", "") = "" + | firstChars(a, "") = implode([hd(explode(a))]) + | firstChars("", b) = implode([hd(explode(b))]) + | firstChars(a, b) = implode([hd(explode(a))] @ [hd(explode(b))]); + (* Question 6 *) fun sortPairs((a, b), (c, d)) = if (a + b) > (c + d) then ((a, b), (c, d)) else ((c, d), (a, b)); diff --git a/src/sml_practice/ica6.sml b/src/ica06/ica06.sml similarity index 100% rename from src/sml_practice/ica6.sml rename to src/ica06/ica06.sml diff --git a/src/quiz04-to-be-merged/quiz04.sml b/src/quiz04/quiz04.sml similarity index 100% rename from src/quiz04-to-be-merged/quiz04.sml rename to src/quiz04/quiz04.sml diff --git a/quiz07.sml b/src/quiz04/quiz07.sml similarity index 100% rename from quiz07.sml rename to src/quiz04/quiz07.sml diff --git a/sml_practice.sml b/src/sml_practice/sml_practice.sml similarity index 100% rename from sml_practice.sml rename to src/sml_practice/sml_practice.sml diff --git a/SML Practice.pdf b/src/sml_practice/spec.pdf similarity index 100% rename from SML Practice.pdf rename to src/sml_practice/spec.pdf