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/week4 | |
| parent | Added student numbers (diff) | |
update to fp2 yay, public and licence
Diffstat (limited to 'fp1/week4')
| -rw-r--r-- | fp1/week4/camil/5.4 | 5 | ||||
| -rw-r--r-- | fp1/week4/camil/StdSet.dcl | 25 | ||||
| -rw-r--r-- | fp1/week4/camil/StdSet.icl | 64 | ||||
| -rw-r--r-- | fp1/week4/mart/5.4.txt | 4 | ||||
| -rw-r--r-- | fp1/week4/mart/StdSet.dcl | 25 | ||||
| -rw-r--r-- | fp1/week4/mart/StdSet.icl | 54 | ||||
| -rw-r--r-- | fp1/week4/week4.tar.gz | bin | 0 -> 890 bytes | 
7 files changed, 177 insertions, 0 deletions
| diff --git a/fp1/week4/camil/5.4 b/fp1/week4/camil/5.4 new file mode 100644 index 0000000..accd855 --- /dev/null +++ b/fp1/week4/camil/5.4 @@ -0,0 +1,5 @@ +1.  Optelling in de gehele getallen is commutatief, dit maakt dus niet uit. +2.  Het verschil tussen 4-2=2 en 2-4=-2. +    Algemeen: het verschill tussen (-) a b = a-b en flip (-) a b = b-a, dus (-) a b = - flip (-) a b +3.  Vermenigvuldiging in de gehele getallen is commutatief, dit maakt dus niet uit. +3.  Het verschil tussen 4/2=2 en 2/4=0. diff --git a/fp1/week4/camil/StdSet.dcl b/fp1/week4/camil/StdSet.dcl new file mode 100644 index 0000000..6cad7f1 --- /dev/null +++ b/fp1/week4/camil/StdSet.dcl @@ -0,0 +1,25 @@ +definition module StdSet
 +
 +import StdClass
 +
 +::	Set a
 +
 +toSet			:: [a]             -> Set a | Eq a
 +fromSet			:: (Set a)         -> [a]
 +
 +isEmptySet		:: (Set a)         -> Bool
 +isDisjoint		:: (Set a) (Set a) -> Bool  | Eq a
 +isSubset		:: (Set a) (Set a) -> Bool  | Eq a
 +isStrictSubset	:: (Set a) (Set a) -> Bool  | Eq a
 +memberOfSet		:: a       (Set a) -> Bool  | Eq a
 +union           :: (Set a) (Set a) -> Set a | Eq a
 +intersection	:: (Set a) (Set a) -> Set a | Eq a
 +nrOfElements	:: (Set a) -> Int
 +without			:: (Set a) (Set a) -> Set a | Eq a
 +
 +product			:: (Set a) (Set b) -> Set (a,b)
 +
 +instance zero (Set a)
 +instance ==   (Set a) | Eq a
 +
 +powerSet		:: (Set a)         -> Set (Set a)
 diff --git a/fp1/week4/camil/StdSet.icl b/fp1/week4/camil/StdSet.icl new file mode 100644 index 0000000..651c869 --- /dev/null +++ b/fp1/week4/camil/StdSet.icl @@ -0,0 +1,64 @@ +implementation module StdSet
 +
 +import StdEnv
 +import StdClass
 +
 +::	Set a :== [a]
 +
 +toSet			:: [a]             -> Set a | Eq a
 +toSet l = toSet` l []
 +where 
 +    toSet` [] s = s
 +    toSet` [x:xs] s = toSet` xs (join x s)
 +    where
 +        join :: a (Set a) -> Set a | Eq a
 +        join e s
 +            | memberOfSet e s = s
 +            | otherwise = s ++ [e]
 +
 +fromSet			:: (Set a)         -> [a]
 +fromSet s = s
 +
 +isEmptySet		:: (Set a)         -> Bool
 +isEmptySet [] = True
 +isEmptySet _ = False
 +
 +isDisjoint		:: (Set a) (Set a) -> Bool  | Eq a
 +isDisjoint s1 s2 = length (intersection s1 s2) == 0
 +
 +isSubset		:: (Set a) (Set a) -> Bool  | Eq a
 +isSubset s1 s2 = nrOfElements (intersection s1 s2) == nrOfElements s1
 +
 +isStrictSubset	:: (Set a) (Set a) -> Bool  | Eq a
 +isStrictSubset s1 s2 = isSubset s1 s2 && s1 <> s2
 +
 +memberOfSet		:: a       (Set a) -> Bool  | Eq a
 +memberOfSet e [] = False
 +memberOfSet e [x:xs] 
 +    | e == x = True
 +    | otherwise = memberOfSet e xs
 +
 +union           :: (Set a) (Set a) -> Set a | Eq a
 +union s1 s2 = toSet (s1 ++ s2)
 +
 +intersection	:: (Set a) (Set a) -> Set a | Eq a
 +intersection s1 s2 = [e \\ e <- s1 | memberOfSet e s2]
 +
 +nrOfElements	:: (Set a) -> Int
 +nrOfElements s = length (fromSet s)
 +
 +without			:: (Set a) (Set a) -> Set a | Eq a
 +without s1 s2 = [e \\ e <- s1 | (memberOfSet e s2) == False]
 +
 +product			:: (Set a) (Set b) -> Set (a,b)
 +product s1 s2 = [(e1,e2) \\ e1 <- s1, e2 <- s2]
 +
 +instance zero (Set a)
 +where zero = []
 +
 +instance ==   (Set a) | Eq a 
 +where (==) s1 s2 = isSubset s1 s2 && isSubset s2 s1
 +
 +powerSet		:: (Set a)         -> Set (Set a)
 +powerSet [] = [zero]
 +powerSet [e:es] = map ((++) [e]) (powerSet es) ++ powerSet es
\ No newline at end of file diff --git a/fp1/week4/mart/5.4.txt b/fp1/week4/mart/5.4.txt new file mode 100644 index 0000000..50521d3 --- /dev/null +++ b/fp1/week4/mart/5.4.txt @@ -0,0 +1,4 @@ +1. 4+2 en 2+4. Dit geeft zelfde uitkomst ivm commutativiteit van + +2. 4-2 en 2-4. Dit geeft 2 en -2. - is niet commutitatief. +3. 4*2 en 2*4. Dit geeft zelfde uitkomst ivm commutativiteit van * +4. 4/2 en 2/4. Dit geeft 2 en 0. / is niet commutitatief. diff --git a/fp1/week4/mart/StdSet.dcl b/fp1/week4/mart/StdSet.dcl new file mode 100644 index 0000000..0c702ca --- /dev/null +++ b/fp1/week4/mart/StdSet.dcl @@ -0,0 +1,25 @@ +definition module StdSet
 +
 +import StdClass
 +
 +::	Set a
 +
 +toSet			:: [a]             -> Set a | Eq a
 +fromSet			:: (Set a)         -> [a]
 +
 +isEmptySet		:: (Set a)         -> Bool
 +isDisjoint		:: (Set a) (Set a) -> Bool  | Eq a
 +isSubset		:: (Set a) (Set a) -> Bool  | Eq a
 +isStrictSubset	:: (Set a) (Set a) -> Bool  | Eq a
 +memberOfSet		:: a       (Set a) -> Bool  | Eq a
 +union           :: (Set a) (Set a) -> Set a | Eq a
 +intersection	:: (Set a) (Set a) -> Set a | Eq a
 +nrOfElements	:: (Set a) -> Int
 +without			:: (Set a) (Set a) -> Set a | Eq a
 +
 +product			:: (Set a) (Set b) -> Set (a,b)
 +
 +instance zero (Set a)
 +instance ==   (Set a) | Eq a
 +
 +powerSet		:: (Set a)         -> Set (Set a) | Eq a
 diff --git a/fp1/week4/mart/StdSet.icl b/fp1/week4/mart/StdSet.icl new file mode 100644 index 0000000..ecb2e60 --- /dev/null +++ b/fp1/week4/mart/StdSet.icl @@ -0,0 +1,54 @@ +implementation module StdSet
 +
 +import StdEnv
 +import StdClass
 +
 +::	Set a = Set [a]
 +
 +toSet	:: [a]             -> Set a | Eq a
 +toSet s = Set (removeDup s)
 +
 +fromSet	:: (Set a)         -> [a]
 +fromSet (Set s) = s
 +
 +isEmptySet	:: (Set a)         -> Bool
 +isEmptySet s = isEmpty (fromSet s)
 +
 +isDisjoint	:: (Set a) (Set a) -> Bool  | Eq a
 +isDisjoint s1 s2 = nrOfElements (intersection s1 s2) == 0
 +
 +isSubset	:: (Set a) (Set a) -> Bool  | Eq a
 +isSubset s1 s2 = nrOfElements s1 == nrOfElements (intersection s1 s2)
 +
 +isStrictSubset	:: (Set a) (Set a) -> Bool  | Eq a
 +isStrictSubset s1 s2 = isSubset s1 s2 && nrOfElements s1 < nrOfElements s2
 +
 +memberOfSet	:: a       (Set a) -> Bool  | Eq a
 +memberOfSet a (Set []) = False
 +memberOfSet a (Set [x:xs]) = a == x || memberOfSet a (Set xs)
 +
 +union	:: (Set a) (Set a) -> Set a | Eq a
 +union (Set s1) (Set s2) = toSet (s1 ++ s2)
 +
 +intersection	:: (Set a) (Set a) -> Set a | Eq a
 +intersection (Set s1) s2 = Set [e \\ e <- s1 | memberOfSet e s2]
 +
 +nrOfElements	:: (Set a) -> Int
 +nrOfElements s = length (fromSet s)
 +
 +without	:: (Set a) (Set a) -> Set a | Eq a
 +without (Set s1) s2 = Set [e \\ e <- s1 | not (memberOfSet e s2)]
 +
 +product	:: (Set a) (Set b) -> Set (a,b)
 +product (Set s1) (Set s2) = Set [(e1, e2) \\ e1 <- s1, e2 <- s2]
 +
 +instance zero (Set a)
 +where zero = Set []
 +
 +instance == (Set a) | Eq a
 +where (==) s1 s2 = isSubset s1 s2 && isSubset s2 s1
 +
 +powerSet	:: (Set a)         -> Set (Set a) | Eq a
 +powerSet (Set []) = Set [(Set [])]
 +powerSet (Set [e:xs]) = union (powerSet (Set xs))
 +	(Set [union (Set [e]) x \\ x <- fromSet (powerSet (Set xs))])
 diff --git a/fp1/week4/week4.tar.gz b/fp1/week4/week4.tar.gzBinary files differ new file mode 100644 index 0000000..0258701 --- /dev/null +++ b/fp1/week4/week4.tar.gz | 
