diff options
| author | Camil Staps | 2016-02-02 19:24:50 +0100 | 
|---|---|---|
| committer | Camil Staps | 2016-02-02 19:24:50 +0100 | 
| commit | a7d7542dc646a5fd124ef71e71ce260889f1701b (patch) | |
| tree | 04ed89503bbb3cc9933273a1326a53ca724c3492 /1415/fp1/week2/camil | |
| parent | week6 camil: working positioning of lines by putting empties at left and righ... (diff) | |
Diffstat (limited to '1415/fp1/week2/camil')
| -rw-r--r-- | 1415/fp1/week2/camil/Makefile | 4 | ||||
| -rw-r--r-- | 1415/fp1/week2/camil/StdT.dcl | 18 | ||||
| -rw-r--r-- | 1415/fp1/week2/camil/StdT.icl | 37 | ||||
| -rw-r--r-- | 1415/fp1/week2/camil/TupleOverloading.dcl | 25 | ||||
| -rw-r--r-- | 1415/fp1/week2/camil/TupleOverloading.icl | 53 | ||||
| -rw-r--r-- | 1415/fp1/week2/camil/VectorOverloading.dcl | 14 | ||||
| -rw-r--r-- | 1415/fp1/week2/camil/VectorOverloading.icl | 37 | 
7 files changed, 188 insertions, 0 deletions
| diff --git a/1415/fp1/week2/camil/Makefile b/1415/fp1/week2/camil/Makefile new file mode 100644 index 0000000..9095df9 --- /dev/null +++ b/1415/fp1/week2/camil/Makefile @@ -0,0 +1,4 @@ +all: +	clm StdT -o StdT +	clm TupleOverloading -o TupleOverloading +	clm VectorOverloading -o VectorOverloading diff --git a/1415/fp1/week2/camil/StdT.dcl b/1415/fp1/week2/camil/StdT.dcl new file mode 100644 index 0000000..ca97fdc --- /dev/null +++ b/1415/fp1/week2/camil/StdT.dcl @@ -0,0 +1,18 @@ +definition module StdT
 +
 +import StdOverloaded
 +
 +::	T
 +
 +instance ==			T
 +instance <			T
 +
 +instance zero		T
 +instance +			T
 +instance -			T
 +
 +instance toInt		T
 +instance fromInt	T
 +
 +instance toString	T
 +instance fromString	T
 diff --git a/1415/fp1/week2/camil/StdT.icl b/1415/fp1/week2/camil/StdT.icl new file mode 100644 index 0000000..03c8645 --- /dev/null +++ b/1415/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}
 diff --git a/1415/fp1/week2/camil/TupleOverloading.dcl b/1415/fp1/week2/camil/TupleOverloading.dcl new file mode 100644 index 0000000..6831948 --- /dev/null +++ b/1415/fp1/week2/camil/TupleOverloading.dcl @@ -0,0 +1,25 @@ +definition module TupleOverloading
 +
 +import StdEnv
 +
 +instance +    (a,b)   | + a & + b
 +instance +    (a,b,c) | + a & + b & + c
 +
 +
 +instance -    (a,b)   | - a & - b
 +instance -    (a,b,c) | - a & - b & - c
 +
 +instance *    (a,b)   | * a & * b
 +instance *    (a,b,c) | * a & * b & * c
 +
 +instance /    (a,b)   | / a & / b
 +instance /    (a,b,c) | / a & / b & / c
 +
 +instance zero (a,b)   | zero a & zero b
 +instance zero (a,b,c) | zero a & zero b & zero c
 +
 +instance one  (a,b)   | one a & one b
 +instance one  (a,b,c) | one a & one b & one c
 +
 +instance ~    (a,b)   | ~ a & ~ b
 +instance ~    (a,b,c) | ~ a & ~ b & ~ c
 diff --git a/1415/fp1/week2/camil/TupleOverloading.icl b/1415/fp1/week2/camil/TupleOverloading.icl new file mode 100644 index 0000000..0ea437d --- /dev/null +++ b/1415/fp1/week2/camil/TupleOverloading.icl @@ -0,0 +1,53 @@ +/**
 + * Mart Lubbers, s4109503
 + * Camil Staps, s4498062
 + */
 +
 +implementation module TupleOverloading
 +
 +import StdEnv
 +
 +instance +    (a,b)   | + a & + b                where
 +	+ (a,b) (c,d) = (a+c,b+d)
 +instance +    (a,b,c) | + a & + b & + c          where
 +	+ (a,b,c) (d,e,f) = (a+d,b+e,c+f)
 +
 +instance -    (a,b)   | - a & - b                where
 +	- (a,b) (c,d) = (a-c,b-d)
 +instance -    (a,b,c) | - a & - b & - c          where
 +	- (a,b,c) (d,e,f) = (a-d,b-e,c-f)
 +
 +instance *    (a,b)   | * a & * b                where
 +	* (a,b) (c,d) = (a*c,b*d)
 +instance *    (a,b,c) | * a & * b & * c          where
 +	* (a,b,c) (d,e,f) = (a*d,b*e,c*f)
 +
 +instance /    (a,b)   | / a & / b                where
 +	/ (a,b) (c,d) = (a/c,b/d)
 +instance /    (a,b,c) | / a & / b & / c          where
 +	/ (a,b,c) (d,e,f) = (a/d,b/e,c/f)
 +
 +instance zero (a,b)   | zero a & zero b          where
 +	zero = (zero, zero)
 +instance zero (a,b,c) | zero a & zero b & zero c where
 +	zero = (zero, zero, zero)
 +
 +instance one  (a,b)   | one a & one b            where
 +	one = (one, one)
 +instance one  (a,b,c) | one a & one b & one c    where
 +	one = (one, one, one)
 +
 +instance ~    (a,b)   | ~ a & ~ b                where
 +	~ (a,b) = (~ a, ~ b)
 +instance ~    (a,b,c) | ~ a & ~ b & ~ c          where
 +	~ (a,b,c) = (~ a, ~ b, ~ c)
 +
 +Start  = (test (1,2), test (1,2,3))
 +
 +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
 +         )
 diff --git a/1415/fp1/week2/camil/VectorOverloading.dcl b/1415/fp1/week2/camil/VectorOverloading.dcl new file mode 100644 index 0000000..76f8520 --- /dev/null +++ b/1415/fp1/week2/camil/VectorOverloading.dcl @@ -0,0 +1,14 @@ +definition module VectorOverloading
 +
 +import StdEnv
 +
 +:: Vector2 a = {x0 :: a, x1 :: a}
 +
 +instance ==   (Vector2 a) | == a
 +instance zero (Vector2 a) | zero a
 +instance one  (Vector2 a) | one a
 +instance ~    (Vector2 a) | ~ a
 +instance +    (Vector2 a) | + a
 +instance -    (Vector2 a) | - a
 +instance *    (Vector2 a) | * a
 +instance /    (Vector2 a) | / a
 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
 +         )
 | 
