diff options
-rw-r--r-- | files/practicum/GetallenRaden.icl | 13 | ||||
-rw-r--r-- | files/practicum/Origami.icl | 17 | ||||
-rw-r--r-- | files/practicum/StdDynSet.dcl | 24 | ||||
-rw-r--r-- | files/practicum/StdDynSet.icl | 44 | ||||
-rw-r--r-- | files/practicum/StdIOMonad.dcl | 39 | ||||
-rw-r--r-- | files/practicum/StdIOMonad.icl | 15 | ||||
-rw-r--r-- | files/practicum/StdListMonad.dcl | 7 | ||||
-rw-r--r-- | files/practicum/StdListMonad.icl | 7 | ||||
-rw-r--r-- | files/practicum/StdMaybeMonad.dcl | 9 | ||||
-rw-r--r-- | files/practicum/StdMaybeMonad.icl | 10 | ||||
-rw-r--r-- | files/practicum/StdQ.icl | 2 | ||||
-rw-r--r-- | files/practicum/StdSet.icl | 24 | ||||
-rw-r--r-- | files/practicum/StdSortList.icl | 2 | ||||
-rw-r--r-- | files/practicum/StdStack.icl | 2 | ||||
-rw-r--r-- | files/practicum/StdStateMonad.dcl | 11 | ||||
-rw-r--r-- | files/practicum/StdStateMonad.icl | 16 |
16 files changed, 210 insertions, 32 deletions
diff --git a/files/practicum/GetallenRaden.icl b/files/practicum/GetallenRaden.icl new file mode 100644 index 0000000..f03750a --- /dev/null +++ b/files/practicum/GetallenRaden.icl @@ -0,0 +1,13 @@ +module GetallenRaden
+
+/* Dynamics werken alleen met de 32-bit versie van de Clean compiler.
+ (*) Gebruik Environment 'Experimental'
+ (*) In Project:Project Options: zet vlag 'Enable dynamics' aan
+*/
+import StdEnv
+import StdDynamic, StdDynamicFileIO // nodig voor dynamics en dynamics in files
+import StdFileSelect // platform file-selector dialoog
+
+Start :: *World -> *World
+Start world
+ = world
diff --git a/files/practicum/Origami.icl b/files/practicum/Origami.icl index 304ca73..3c4dcc4 100644 --- a/files/practicum/Origami.icl +++ b/files/practicum/Origami.icl @@ -6,15 +6,18 @@ Start = and [ sum` [1 .. 5] == sum [1 .. 5]
, prod` [1 .. 5] == prod [1 .. 5]
, flatten` [[],[1],[1,2],[1,2,3]] == flatten [[],[1],[1,2],[1,2,3]]
+ , length` [1 .. 5] == length [1 .. 5]
, reverse` [1 .. 5] == reverse [1 .. 5]
+ , filter` isEven [1 .. 100] == filter isEven [1 .. 100]
, takeWhile` ((<>) 0) [1,2,3,0,4,5,6] == takeWhile ((<>) 0) [1,2,3,0,4,5,6]
, maxList` [1 .. 5] == maxList [1 .. 5]
]
-sum` = ...
-prod` = ...
-flatten` = ...
-length` = ...
-reverse` = ...
-takeWhile` = ...
-maxList` = ...
+sum` xs = ...
+prod` xs = ...
+flatten` xs = ...
+length` xs = ...
+reverse` xs = ...
+filter` p xs = ...
+takeWhile` p xs = ...
+maxList` xs = ...
diff --git a/files/practicum/StdDynSet.dcl b/files/practicum/StdDynSet.dcl new file mode 100644 index 0000000..de9a9b7 --- /dev/null +++ b/files/practicum/StdDynSet.dcl @@ -0,0 +1,24 @@ +definition module StdDynSet
+
+import StdOverloaded
+
+class Set a | TC, ==, toString a
+
+:: Set
+
+instance zero Set
+instance toString Set
+instance == Set
+
+toSet :: a -> Set | Set a
+
+nrOfElts :: Set -> Int
+isEmptySet :: Set -> Bool
+
+memberOfSet :: a Set -> Bool | Set a
+isSubset :: Set Set -> Bool
+isStrictSubset :: Set Set -> Bool
+
+union :: Set Set -> Set
+intersection :: Set Set -> Set
+without :: Set Set -> Set
diff --git a/files/practicum/StdDynSet.icl b/files/practicum/StdDynSet.icl new file mode 100644 index 0000000..ee43631 --- /dev/null +++ b/files/practicum/StdDynSet.icl @@ -0,0 +1,44 @@ +implementation module StdDynSet
+
+import StdEnv
+import StdDynamic
+
+class Set a | TC, ==, toString a
+
+:: Set = Set [Dynamic]
+
+instance zero Set
+where zero = abort "zero instance voor Set nog niet geimplementeerd.\n"
+
+instance toString Set
+where toString a = abort "toString instance voor Set nog niet geimplementeerd.\n"
+
+instance == Set
+where == a b = abort "== instance voor Set nog niet geimplementeerd.\n"
+
+toSet :: a -> Set | Set a
+toSet a = abort "toSet nog niet geimplementeerd.\n"
+
+nrOfElts :: Set -> Int
+nrOfElts a = abort "nrOfElts nog niet geimplementeerd.\n"
+
+isEmptySet :: Set -> Bool
+isEmptySet a = abort "isEmptySet nog niet geimplementeerd.\n"
+
+memberOfSet :: a Set -> Bool | Set a
+memberOfSet x a = abort "memberOfSet nog niet geimplementeerd.\n"
+
+isSubset :: Set Set -> Bool
+isSubset a b = abort "isSubset nog niet geimplementeerd.\n"
+
+isStrictSubset :: Set Set -> Bool
+isStrictSubset a b = abort "isStrictSubset nog niet geimplementeerd.\n"
+
+union :: Set Set -> Set
+union a b = abort "union nog niet geimplementeerd.\n"
+
+intersection :: Set Set -> Set
+intersection a b = abort "intersection nog niet geimplementeerd.\n"
+
+without :: Set Set -> Set
+without a b = abort "without nog niet geimplementeerd.\n"
diff --git a/files/practicum/StdIOMonad.dcl b/files/practicum/StdIOMonad.dcl new file mode 100644 index 0000000..a37a979 --- /dev/null +++ b/files/practicum/StdIOMonad.dcl @@ -0,0 +1,39 @@ +definition module StdIOMonad
+
+// Deze module verpakt een aantal StdFile functies in een monadische jas
+
+import StdMonad, StdMaybeMonad
+
+:: IO a
+:: Void = Void
+:: Filemode = Lees | Schrijf
+:: Filenaam :== String
+:: Filehandle
+
+// voer monadische I/O actie uit op de wereld:
+doIO :: (IO a) *World -> (a,*World)
+
+// IO is een monad:
+instance return IO
+instance >>= IO
+
+// lees regel van de console:
+read :: IO String
+
+// schrijf regel naar de console:
+write :: String -> IO Void
+
+// open de file met gegeven filenaam en mode:
+open :: Filenaam Filemode -> IO (Maybe Filehandle)
+
+// sluit de file met gegeven filenaam:
+close :: Filehandle -> IO Bool
+
+// bepaal of het lezen van de file klaar is:
+eof :: Filehandle -> IO Bool
+
+// lees een regel van een file:
+readline :: Filehandle -> IO (Maybe String)
+
+// schrijf een regel naar een file:
+writeline :: String Filehandle -> IO Bool
diff --git a/files/practicum/StdIOMonad.icl b/files/practicum/StdIOMonad.icl new file mode 100644 index 0000000..c8ddaa5 --- /dev/null +++ b/files/practicum/StdIOMonad.icl @@ -0,0 +1,15 @@ +implementation module StdIOMonad
+
+// Deze module verpakt StdFile in een monadische jas
+
+import StdFile
+import StdMonad
+
+:: IO a // kies een geschikte representatie voor IO
+:: Filemode = Lees | Schrijf
+:: Filenaam :== String
+:: Filehandle // kies een geschikte representatie voor Filehandle
+
+instance toInt Filemode where
+ toInt Lees = FReadText
+ toInt Schrijf = FWriteText
diff --git a/files/practicum/StdListMonad.dcl b/files/practicum/StdListMonad.dcl new file mode 100644 index 0000000..576ef55 --- /dev/null +++ b/files/practicum/StdListMonad.dcl @@ -0,0 +1,7 @@ +definition module StdListMonad
+
+import StdMonad
+
+instance return []
+instance >>= []
+instance fail []
diff --git a/files/practicum/StdListMonad.icl b/files/practicum/StdListMonad.icl new file mode 100644 index 0000000..b3b3d62 --- /dev/null +++ b/files/practicum/StdListMonad.icl @@ -0,0 +1,7 @@ +implementation module StdListMonad
+
+import StdMonad
+
+instance return [] where return x = [x]
+instance >>= [] where >>= xs f = [y \\ x <- xs, y <- f x]
+instance fail [] where fail = []
diff --git a/files/practicum/StdMaybeMonad.dcl b/files/practicum/StdMaybeMonad.dcl new file mode 100644 index 0000000..e9ebec1 --- /dev/null +++ b/files/practicum/StdMaybeMonad.dcl @@ -0,0 +1,9 @@ +definition module StdMaybeMonad
+
+import StdMonad
+
+:: Maybe a = Nothing | Just a
+
+instance return Maybe
+instance >>= Maybe
+instance fail Maybe
diff --git a/files/practicum/StdMaybeMonad.icl b/files/practicum/StdMaybeMonad.icl new file mode 100644 index 0000000..1c6277d --- /dev/null +++ b/files/practicum/StdMaybeMonad.icl @@ -0,0 +1,10 @@ +implementation module StdMaybeMonad
+
+import StdMonad
+
+:: Maybe a = Nothing | Just a
+
+instance return Maybe where return x = Just x
+instance >>= Maybe where >>= (Just x) f = f x
+ >>= Nothing f = Nothing
+instance fail Maybe where fail = Nothing
diff --git a/files/practicum/StdQ.icl b/files/practicum/StdQ.icl index 84ff69e..9883f91 100644 --- a/files/practicum/StdQ.icl +++ b/files/practicum/StdQ.icl @@ -2,4 +2,4 @@ implementation module StdQ import StdEnv
-:: Q = ...
+:: Q = ... // maak deze type definitie af
diff --git a/files/practicum/StdSet.icl b/files/practicum/StdSet.icl index 6cad7f1..b152f37 100644 --- a/files/practicum/StdSet.icl +++ b/files/practicum/StdSet.icl @@ -1,25 +1,5 @@ -definition module StdSet
+implementation module StdSet
-import StdClass
+import StdEnv
:: 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/files/practicum/StdSortList.icl b/files/practicum/StdSortList.icl index 5621887..20acaf7 100644 --- a/files/practicum/StdSortList.icl +++ b/files/practicum/StdSortList.icl @@ -2,4 +2,4 @@ implementation module StdSortList import StdEnv
-:: SortList a
+:: SortList a = ... // maak deze type definitie af (mag ook een synoniem type zijn, maar gebruik dan :== in plaats van =)
diff --git a/files/practicum/StdStack.icl b/files/practicum/StdStack.icl index f8583d5..4b3a1f8 100644 --- a/files/practicum/StdStack.icl +++ b/files/practicum/StdStack.icl @@ -2,7 +2,7 @@ implementation module StdStack import StdEnv
-:: Stack a
+:: Stack a = ... // maak deze type definitie af (mag ook een synoniem type zijn, maar gebruik dan :== in plaats van =)
Start = ( "s0 = newStack = ", s0,'\n'
, "s1 = push 1 s0 = ", s1,'\n'
diff --git a/files/practicum/StdStateMonad.dcl b/files/practicum/StdStateMonad.dcl new file mode 100644 index 0000000..a825dbc --- /dev/null +++ b/files/practicum/StdStateMonad.dcl @@ -0,0 +1,11 @@ +definition module StdStateMonad
+
+import StdMonad
+
+:: ST s a
+
+instance return (ST s)
+instance >>= (ST s)
+
+mkST :: (s -> *(a,s)) -> ST s a
+unST :: (ST s a) -> s -> *(a, s)
diff --git a/files/practicum/StdStateMonad.icl b/files/practicum/StdStateMonad.icl new file mode 100644 index 0000000..527ac5c --- /dev/null +++ b/files/practicum/StdStateMonad.icl @@ -0,0 +1,16 @@ +implementation module StdStateMonad
+
+import StdMonad
+
+:: ST s a = ST (s -> (a, s))
+
+instance return (ST s) where return x = ST (\w = (x, w))
+instance >>= (ST s) where >>= (ST f) g = ST (\w = let (a, w1) = f w
+ in unST (g a) w1
+ )
+
+mkST :: (s -> (a,s)) -> ST s a
+mkST f = ST f
+
+unST :: (ST s a) -> s -> (a, s)
+unST (ST f) = f
|