summaryrefslogtreecommitdiff
path: root/fp1/week2/camil/StdT.icl
diff options
context:
space:
mode:
authorMart Lubbers2015-04-16 21:22:20 +0200
committerMart Lubbers2015-04-16 21:22:20 +0200
commit6f604b19d3f5966e5c1d7c4fdf3703bd6ff0861c (patch)
tree96d580507249f7f58368476d9113007d4afcd748 /fp1/week2/camil/StdT.icl
parentAdded student numbers (diff)
update to fp2 yay, public and licence
Diffstat (limited to 'fp1/week2/camil/StdT.icl')
-rw-r--r--fp1/week2/camil/StdT.icl37
1 files changed, 37 insertions, 0 deletions
diff --git a/fp1/week2/camil/StdT.icl b/fp1/week2/camil/StdT.icl
new file mode 100644
index 0000000..03c8645
--- /dev/null
+++ b/fp1/week2/camil/StdT.icl
@@ -0,0 +1,37 @@
+/**
+ * Mart Lubbers, s4109503
+ * Camil Staps, s4498062
+ */
+
+implementation module StdT
+
+import StdEnv
+
+:: T = {m :: Int, s :: Int}
+
+instance == T where == a b = a.m == b.m && a.s == b.s
+instance < T where < a b = a.m < b.m || a.m == b.m && a.s < b.s
+
+instance zero T where zero = {m = zero, s = zero}
+instance + T where + a b = fromInt (toInt a + toInt b)
+instance - T where - a b = if (a < b) zero (fromInt (toInt a - toInt b))
+
+instance toInt T where toInt a = a.m * 60 + a.s
+instance fromInt T where fromInt n = if (n < 0) zero {m = n/60, s = n rem 60}
+
+instance toString T where
+ toString {m = x, s = 0} = toString x +++ ":00"
+ toString a = toString a.m +++ ":" +++ (if (a.s < 10) "0" "") +++ toString a.s
+instance fromString T where
+ fromString s = if (s.[size s - 3] == ':')
+ {m = toInt (s % (0, size s - 4)), s = toInt (s % (size s - 2, size s - 1))}
+ zero
+
+Start :: (Bool, Bool, T, T, T, Int, String, T, T)
+Start = (LOTR == Tea, Tea < LOTR,
+ zero + LOTR, LOTR + Tea, Tea - LOTR,
+ toInt LOTR, toString Tea,
+ fromString "5:40", fromString "foo")
+
+LOTR = {m=178, s=0}
+Tea = {m=0,s=41}