summaryrefslogtreecommitdiff
path: root/week2/mart/VectorOverloading.icl
diff options
context:
space:
mode:
authorMart Lubbers2015-02-10 10:07:28 +0100
committerMart Lubbers2015-02-10 10:07:28 +0100
commit05ffd999512958a5bd1a44e7bc053db5af549ca8 (patch)
tree84ce44bfaa4d94584bdbb2e60c85af5892317eb9 /week2/mart/VectorOverloading.icl
parentweek 2 camil (diff)
week 2 almost finished
Diffstat (limited to 'week2/mart/VectorOverloading.icl')
-rw-r--r--week2/mart/VectorOverloading.icl22
1 files changed, 22 insertions, 0 deletions
diff --git a/week2/mart/VectorOverloading.icl b/week2/mart/VectorOverloading.icl
new file mode 100644
index 0000000..74f6f69
--- /dev/null
+++ b/week2/mart/VectorOverloading.icl
@@ -0,0 +1,22 @@
+implementation module VectorOverloading
+
+import StdEnv
+
+:: Vector2 a = {x0 :: a, x1 :: a}
+
+instance == (Vector2 a) | == a where
+ == a b = a.x0 == b.x0 && a.x1 == b.x1
+instance zero (Vector2 a) | zero a where
+ zero = {x0=zero, x1=zero}
+instance one (Vector2 a) | one a where
+ one = {x0=one, x1=one}
+instance ~ (Vector2 a) | ~ a where
+ ~ a = {x0= ~a.x0, x1= ~a.x1}
+instance + (Vector2 a) | + a where
+ + a b = {x0=a.x0+b.x0, x1=a.x1+b.x1}
+instance - (Vector2 a) | - a where
+ - a b = {x0=a.x0-b.x0, x1=a.x1-b.x1}
+instance * (Vector2 a) | * a where
+ * a b = {x0=a.x0*b.x0, x1=a.x1*b.x1}
+instance / (Vector2 a) | / a where
+ / a b = {x0=a.x0/b.x0, x1=a.x1/b.x1}