diff options
author | Mart Lubbers | 2015-04-16 21:22:20 +0200 |
---|---|---|
committer | Mart Lubbers | 2015-04-16 21:22:20 +0200 |
commit | 6f604b19d3f5966e5c1d7c4fdf3703bd6ff0861c (patch) | |
tree | 96d580507249f7f58368476d9113007d4afcd748 /fp1/week2/mart/VectorOverloading.icl | |
parent | Added student numbers (diff) |
update to fp2 yay, public and licence
Diffstat (limited to 'fp1/week2/mart/VectorOverloading.icl')
-rw-r--r-- | fp1/week2/mart/VectorOverloading.icl | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/fp1/week2/mart/VectorOverloading.icl b/fp1/week2/mart/VectorOverloading.icl new file mode 100644 index 0000000..74f6f69 --- /dev/null +++ b/fp1/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}
|