From a7d7542dc646a5fd124ef71e71ce260889f1701b Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 2 Feb 2016 19:24:50 +0100 Subject: Moved to 1415 directory --- 1415/fp1/week2/camil/VectorOverloading.icl | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 1415/fp1/week2/camil/VectorOverloading.icl (limited to '1415/fp1/week2/camil/VectorOverloading.icl') diff --git a/1415/fp1/week2/camil/VectorOverloading.icl b/1415/fp1/week2/camil/VectorOverloading.icl new file mode 100644 index 0000000..4c9c84a --- /dev/null +++ b/1415/fp1/week2/camil/VectorOverloading.icl @@ -0,0 +1,37 @@ +/** + * Mart Lubbers, s4109503 + * Camil Staps, s4498062 + */ + +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} + +Start = test {x0=1,x1=2} + +test a = ( zero + a == a && a == a + zero + , a - zero == a && a == ~ (zero - a) + , one * a == a && a == a * one + , zero * a == zero && zero == a * zero + , a / one == a + , ~ (~ a) == a + ) -- cgit v1.2.3