finally, week2 done:)
authorMart Lubbers <mart@martlubbers.net>
Sat, 25 Apr 2015 10:18:42 +0000 (12:18 +0200)
committerMart Lubbers <mart@martlubbers.net>
Sat, 25 Apr 2015 10:18:42 +0000 (12:18 +0200)
28 files changed:
fp2/week2/ReturnEnBind.icl [deleted file]
fp2/week2/mart/EchoMonad.icl [deleted file]
fp2/week2/mart/StdIOMonad.dcl
fp2/week2/mart/StdIOMonad.icl
fp2/week2/mart/StdListMonad.dcl [deleted file]
fp2/week2/mart/StdListMonad.icl [deleted file]
fp2/week2/mart/StdMaybe.dcl [deleted file]
fp2/week2/mart/StdMaybe.icl [deleted file]
fp2/week2/mart/StdMaybeMonad.dcl [deleted file]
fp2/week2/mart/StdMaybeMonad.icl [deleted file]
fp2/week2/mart/Test.dcl [new file with mode: 0644]
fp2/week2/mart/Test.icl [new file with mode: 0644]
fp2/week2/mart/ToonFileMonad.icl [deleted file]
fp2/week2/mart/camil.txt
fp2/week2/mart/camil2.txt [deleted file]
fp2/week2/mart/oldold/old/Map.dcl [deleted file]
fp2/week2/mart/oldold/old/Map.icl [deleted file]
fp2/week2/mart/oldold/old/Mappen.icl [deleted file]
fp2/week2/mart/oldold/old/Random.dcl [deleted file]
fp2/week2/mart/oldold/old/Random.icl [deleted file]
fp2/week2/mart/oldold/old/ReturnEnBind.icl [deleted file]
fp2/week2/mart/oldold/old/StdIOMonad.dcl [deleted file]
fp2/week2/mart/oldold/old/StdIOMonad.icl [deleted file]
fp2/week2/mart/oldold/old/StdMaybeMonad.dcl [deleted file]
fp2/week2/mart/oldold/old/StdMaybeMonad.icl [deleted file]
fp2/week2/mart/oldold/old/StdMonad.dcl [deleted file]
fp2/week2/mart/oldold/old/StdMonad.icl [deleted file]
fp2/week2/mart/s4109503_s4498062_fp2_w2.tar.gz [new file with mode: 0644]

diff --git a/fp2/week2/ReturnEnBind.icl b/fp2/week2/ReturnEnBind.icl
deleted file mode 100644 (file)
index 0bece5f..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-module ReturnEnBind\r
-\r
-import StdEnv, Random\r
-\r
-Start = 42\r
-\r
-(bind1) infix 0 :: (St s a) (a -> (St s b)) -> St s b\r
-//(bind1) infix 0 :: (s -> *(a,s)) (a -> (a -> *(a,s))) -> (s -> *(b,s))\r
-(bind1) f1 f2 = \st0 f2 (fst (f1 st0) (snd (f1 st0))\r
-//     (r, st1) = f1 st0\r
-//(bind) f f2 :== \st0 -> let (r,st1) = f st0\r
-//      in f2 r st1\r
-\r
-\r
-som2 :: (RandomSeed -> (Int,RandomSeed))\r
-som2 ...\r
-\r
-seqList1 :: [St s a] -> St s [a]\r
-seqList1 ...\r
diff --git a/fp2/week2/mart/EchoMonad.icl b/fp2/week2/mart/EchoMonad.icl
deleted file mode 100644 (file)
index 3bcab11..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-module EchoMonad\r
-\r
-import StdString               // expliciete import uit StdEnv om nameclash met StdFunc / StdIOMonad te voorkomen\r
-import StdIOMonad\r
-import StdMaybeMonad\r
-\r
-Start :: *World -> (Void,*World)\r
-Start world = doIO echo world\r
-\r
-echo :: IO Void\r
-echo = read >>= \regel ->\r
-       if (regel == "\n")\r
-          (return Void) \r
-          (write regel >>= \_ -> echo)\r
index 0801928..580efaa 100644 (file)
@@ -2,14 +2,14 @@ definition module StdIOMonad
 \r
 //     Deze module verpakt een aantal StdFile functies in een monadische jas\r
 \r
-import StdMonad, StdMaybeMonad\r
+import StdMonad, StdMaybe\r
 \r
 :: IO a\r
 :: *W\r
 :: Void       = Void\r
 :: Filemode   = Lees | Schrijf\r
 :: Filenaam :== String\r
-:: Filehandle\r
+:: Filehandle :== String\r
 \r
 //     voer monadische I/O actie uit op de wereld:\r
 doIO:: (IO a) *World -> *(a, *W)\r
@@ -25,16 +25,16 @@ read                :: IO String
 write          :: String -> IO Void\r
 \r
 //     open de file met gegeven filenaam en mode:\r
-//open         :: Filenaam Filemode -> IO (Maybe Filehandle)\r
+open           :: Filenaam Filemode -> IO (Maybe Filehandle)\r
 \r
 //     sluit de file met gegeven filenaam:\r
-//close                :: Filehandle -> IO Bool\r
-//\r
-////   bepaal of het lezen van de file klaar is:\r
-//eof                  :: Filehandle -> IO Bool\r
-//\r
-////   lees een regel van een file:\r
-//readline     :: Filehandle -> IO (Maybe String)\r
-//\r
-////   schrijf een regel naar een file:\r
-//writeline    :: String Filehandle -> IO Bool\r
+close          :: Filehandle -> IO Bool\r
+\r
+//     bepaal of het lezen van de file klaar is:\r
+eof                    :: Filehandle -> IO Bool\r
+\r
+//     lees een regel van een file:\r
+readline       :: Filehandle -> IO (Maybe String)\r
+\r
+//     schrijf een regel naar een file:\r
+writeline      :: String Filehandle -> IO Bool\r
index b0f2b4f..ffa2857 100644 (file)
@@ -1,7 +1,5 @@
 implementation module StdIOMonad\r
 \r
-//     Deze module verpakt StdFile in een monadische jas\r
-\r
 import StdBool\r
 import StdEnum\r
 import StdFile\r
@@ -19,27 +17,25 @@ import StdTuple
 :: Filenaam :== String\r
 :: Filehandle :== String\r
 \r
+// Conversion from our filemodes to StdFile filemodes\r
 instance toInt Filemode where\r
        toInt Lees = FReadText\r
        toInt Schrijf = FWriteText\r
 \r
-//voer monadische I/O actie uit op de wereld:\r
+// Apply the monadic program on the world\r
 doIO:: (IO a) *World -> *(a, *W)\r
 doIO (IO f) w = f (w, [])\r
 \r
+// Lift the value out of the monadic domain\r
 unIO:: (IO a) -> *W -> *(a, *W)\r
 unIO (IO f) = f \r
 \r
-//  IO is een monad:\r
 instance return IO where\r
        return x = IO (\w -> (x, w))\r
 instance >>=    IO where\r
        (>>=) (IO f) g = IO (\w = let (a, w1) = f w in unIO (g a) w1)\r
 \r
-//Start world = doIO (read >>= (\w = return w)) (world, "")\r
-//Start world = doIO (open "camilt.txt" Lees) (world, "")\r
-//Start world = doIO (read >>= (\w = read)) (world, "")\r
-\r
+// Read one line from the console\r
 read:: IO String\r
 read = IO read`\r
        where\r
@@ -50,7 +46,7 @@ read = IO read`
                # (_, world) = fclose io world\r
                = (line, (world, s))\r
 \r
-//     schrijf regel naar de console:\r
+// Write a line from the console\r
 write          :: String -> IO Void\r
 write s = IO (write` s)\r
        where\r
@@ -61,26 +57,7 @@ write s = IO (write` s)
                # (_, world) = fclose io world\r
                = (Void, (world, s))\r
 \r
-\r
-Start world = doIO (\r
-       open "camil.txt" Lees >>= \r
-       \y = eof "camil.txt") world\r
-\r
-//     open de file met gegeven filenaam en mode:\r
-find:: Filehandle *[*(Filehandle, *File)] -> (Maybe *(Filehandle, *File), *[*(Filehandle, *File)]) \r
-find fh fs\r
-# (fhs, fis) = unzip fs\r
-# fhsC = zip2 [0..length fhs] fhs\r
-# index = [(i, h) \\ (i, h) <- fhsC | h == fh]\r
-| length index == 0 = (Nothing, zip2 fhs fis)\r
-# index = fst (hd index)\r
-# (fis1, fis2) = splitAt index fis\r
-# (fhs1, fhs2) = splitAt index fhs\r
-# (thefile, fis2) = splitAt 1 fis2\r
-# (thehandle, fhs2) = splitAt 1 fhs2\r
-= (Just (hd thehandle, hd thefile), zip2 (fhs1 ++ fhs2) (fis1 ++ fis2))\r
-\r
-\r
+// Open a file\r
 open:: Filenaam Filemode -> IO (Maybe Filehandle)\r
 open s m = IO (open` s m)\r
        where\r
@@ -90,13 +67,14 @@ open s m = IO (open` s m)
                # (ok, file, world) = fopen fp (toInt m) world\r
                = (Just fp, (world, [(fp, file):fs]))\r
 \r
-//     sluit de file met gegeven filenaam:\r
+// Close a file. If the file can't be closed by the system the program will\r
+// abort\r
 close:: Filehandle -> IO Bool\r
 close fh = IO (close` fh)\r
        where\r
                close`:: Filehandle *W -> *(Bool, *W)\r
                close` fp (world, fs)\r
-               # (currentfiletuple, fs) = find fp fs\r
+               # (currentfiletuple, fs) = getFH fp fs\r
                | isNothing currentfiletuple = (False, (world, fs))\r
                # (currentfh, currentfile) = fromJust currentfiletuple\r
                # (ok, world) = fclose currentfile world\r
@@ -104,21 +82,57 @@ close fh = IO (close` fh)
                | otherwise = (True, (world, fs))\r
                \r
 \r
-//     bepaal of het lezen van de file klaar is:\r
+// Determine if the file is at the end. This will abort when the file is not\r
+// open or error if the file is not opened for reading.\r
 eof                    :: Filehandle -> IO Bool\r
 eof fh = IO (eof` fh)\r
        where \r
                eof`:: Filehandle *W -> *(Bool, *W)\r
                eof` fp (world, fs)\r
-               # (currentfiletuple, fs) = find fp fs\r
+               # (currentfiletuple, fs) = getFH fp fs\r
                | isNothing currentfiletuple = abort "Can't do eof on non-existing file"\r
                # (currentfh, currentfile) = fromJust currentfiletuple\r
                # (ok, file) = fend currentfile\r
                = (ok, (world, [(currentfh, file):fs]))\r
 \r
-//     lees een regel van een file:\r
-//readline     :: Filehandle -> IO (Maybe String)\r
-\r
+// Read one line from a file (including newline). This will abort when the file\r
+// is not open or error if the file is not opened for reading.\r
+readline       :: Filehandle -> IO (Maybe String)\r
+readline fh = IO (readline` fh)\r
+       where\r
+               readline` :: Filehandle *W -> *(Maybe String, *W)\r
+               readline` fh (world, fs)\r
+               # (currentfiletuple, fs) = getFH fh fs\r
+               | isNothing currentfiletuple = abort "File not open"\r
+               # (currentfh, currentfile) = fromJust currentfiletuple\r
+               # (s, currentfile) = freadline currentfile\r
+               = (Just s, (world, [(currentfh, currentfile):fs]))\r
 \r
-//     schrijf een regel naar een file:\r
+// Write one line from a file (will not append newline). This will abort when\r
+// the file is not open or error if the file is not opened for writing.\r
 writeline      :: String Filehandle -> IO Bool\r
+writeline s fh = IO (writeline` s fh)\r
+       where\r
+               writeline` :: String Filehandle *W -> *(Bool, *W)\r
+               writeline` s fh (world, fs)\r
+               # (currentfiletuple, fs) = getFH fh fs\r
+               | isNothing currentfiletuple = abort "File not open"\r
+               # (currentfh, currentfile) = fromJust currentfiletuple\r
+               # currentfile = fwrites s currentfile\r
+               = (True, (world, [(currentfh, currentfile):fs]))\r
+\r
+// Gets the file associated with the filehandle given, this is done in a very\r
+// ugly way to retain uniqueness...\r
+getFH:: Filehandle *[*(Filehandle, *File)] ->\r
+       (Maybe *(Filehandle, *File), *[*(Filehandle, *File)]) \r
+getFH fh fs\r
+# (fhs, fis) = unzip fs\r
+# fhsC = zip2 [0..length fhs] fhs\r
+# index = [(i, h) \\ (i, h) <- fhsC | h == fh]\r
+| length index == 0 = (Nothing, zip2 fhs fis)\r
+# index = fst (hd index)\r
+# (fis1, fis2) = splitAt index fis\r
+# (fhs1, fhs2) = splitAt index fhs\r
+# (thefile, fis2) = splitAt 1 fis2\r
+# (thehandle, fhs2) = splitAt 1 fhs2\r
+= (Just (hd thehandle, hd thefile), zip2 (fhs1 ++ fhs2) (fis1 ++ fis2))\r
diff --git a/fp2/week2/mart/StdListMonad.dcl b/fp2/week2/mart/StdListMonad.dcl
deleted file mode 100644 (file)
index 576ef55..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-definition module StdListMonad\r
-\r
-import StdMonad\r
-\r
-instance return []\r
-instance >>=    []\r
-instance fail   []\r
diff --git a/fp2/week2/mart/StdListMonad.icl b/fp2/week2/mart/StdListMonad.icl
deleted file mode 100644 (file)
index b3b3d62..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-implementation module StdListMonad\r
-\r
-import StdMonad\r
-\r
-instance return        [] where return x = [x]\r
-instance >>=   [] where >>= xs f = [y \\ x <- xs, y <- f x]\r
-instance fail   [] where fail     = []\r
diff --git a/fp2/week2/mart/StdMaybe.dcl b/fp2/week2/mart/StdMaybe.dcl
deleted file mode 100644 (file)
index 2403683..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-definition module StdMaybe
-
-//     ********************************************************************************
-//     Clean StdLib library module, version 1.0
-//     ********************************************************************************
-
-from StdFunc import :: St;
-from StdOverloaded import class ==(..);
-
-::     Maybe x
-       =       Just x
-       |       Nothing
-
-isJust         :: !(Maybe .x) -> Bool          // case @1 of (Just _) -> True; _ -> False
-isNothing      :: !(Maybe .x) -> Bool          // not o isJust
-fromJust       :: !(Maybe .x) -> .x            // \(Just x) -> x
-
-// for possibly unique elements:
-u_isJust :: !u:(Maybe .x) -> (!Bool, !u:Maybe .x)
-u_isNothing :: !u:(Maybe .x) -> (!Bool, !u:Maybe .x)
-
-accMaybe :: .(St .x .a) !u:(Maybe .x) -> (!Maybe .a,!u:Maybe .x)
-// accMaybe f (Just x) = (Just (fst (f x)),Just (snd (f x)))
-// accMaybe f Nothing  = (Nothing,Nothing)
-
-mapMaybe       :: .(.x -> .y) !(Maybe .x) -> Maybe .y
-// mapMaybe f (Just x) = Just (f x)
-// mapMaybe f Nothing  = Nothing
-
-instance ==       (Maybe x) | == x
-//     Nothing==Nothing
-//     Just a ==Just b <= a==b
-
-maybeToList :: !(Maybe .a) -> [.a];
-//     returns list with no or one element
-
-listToMaybe :: ![.a] -> .Maybe .a;
-//     returns Just head of list if possible
-
-catMaybes :: ![Maybe .a] -> .[.a];
-//     catMaybes ms =  [ m \\ Just m <- ms ]
diff --git a/fp2/week2/mart/StdMaybe.icl b/fp2/week2/mart/StdMaybe.icl
deleted file mode 100644 (file)
index 4eed325..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-implementation module StdMaybe
-
-//     ********************************************************************************
-//     Clean StdLib library module, version 1.0
-//     ********************************************************************************
-
-from StdFunc import :: St;
-from StdOverloaded import class ==(..);
-
-::     Maybe x
-       =       Just x
-       |       Nothing
-
-isJust :: !(Maybe .x) -> Bool
-isJust Nothing = False
-isJust _               = True
-
-isNothing :: !(Maybe .x) -> Bool
-isNothing Nothing      = True
-isNothing _            = False
-
-u_isJust :: !u:(Maybe .x) -> (!Bool, !u:Maybe .x)
-u_isJust nothing=:Nothing
-       = (False, nothing)
-u_isJust just
-       = (True, just)
-
-u_isNothing :: !u:(Maybe .x) -> (!Bool, !u:Maybe .x)
-u_isNothing nothing=:Nothing
-       = (True, nothing)
-u_isNothing just
-       = (False,just)
-
-fromJust :: !(Maybe .x) -> .x
-fromJust (Just x) = x
-
-accMaybe :: .(St .x .a) !u:(Maybe .x) -> (!Maybe .a,!u:Maybe .x)
-accMaybe f (Just x)
-       # (a,x) = f x
-       = (Just a,Just x)
-accMaybe _ nothing
-       = (Nothing,nothing)
-
-mapMaybe :: .(.x -> .y) !(Maybe .x) -> Maybe .y
-mapMaybe f (Just x) = Just (f x)
-mapMaybe _ nothing  = Nothing
-
-instance == (Maybe x) | == x where
-       (==) Nothing  maybe     = case maybe of
-                                                       Nothing -> True
-                                                       just    -> False
-       (==) (Just a) maybe     = case maybe of
-                                                       Just b  -> a==b
-                                                       nothing -> False
-
-maybeToList :: !(Maybe .a) -> [.a];
-maybeToList Nothing    =  []
-maybeToList (Just a)   =  [a]
-
-listToMaybe :: ![.a] -> .Maybe .a;
-listToMaybe []         =  Nothing
-listToMaybe [a:_]      =  Just a
-catMaybes :: ![Maybe .a] -> .[.a];
-catMaybes ms           =  [ m \\ Just m <- ms ]
diff --git a/fp2/week2/mart/StdMaybeMonad.dcl b/fp2/week2/mart/StdMaybeMonad.dcl
deleted file mode 100644 (file)
index e9ebec1..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-definition module StdMaybeMonad\r
-\r
-import StdMonad\r
-\r
-:: Maybe a = Nothing | Just a\r
-\r
-instance return        Maybe\r
-instance >>=   Maybe\r
-instance fail   Maybe\r
diff --git a/fp2/week2/mart/StdMaybeMonad.icl b/fp2/week2/mart/StdMaybeMonad.icl
deleted file mode 100644 (file)
index 1c6277d..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-implementation module StdMaybeMonad\r
-\r
-import StdMonad\r
-\r
-:: Maybe a = Nothing | Just a\r
-\r
-instance return        Maybe where return x       = Just x\r
-instance >>=   Maybe where >>= (Just x) f = f x\r
-                            >>= Nothing  f = Nothing\r
-instance fail   Maybe where fail           = Nothing\r
diff --git a/fp2/week2/mart/Test.dcl b/fp2/week2/mart/Test.dcl
new file mode 100644 (file)
index 0000000..21f08d1
--- /dev/null
@@ -0,0 +1 @@
+definition module Test
diff --git a/fp2/week2/mart/Test.icl b/fp2/week2/mart/Test.icl
new file mode 100644 (file)
index 0000000..ff32dfe
--- /dev/null
@@ -0,0 +1,13 @@
+implementation module Test\r
+\r
+import StdIOMonad\r
+\r
+// This assumes a file "camil.txt" and writes a line from it to "mart.txt"\r
+Start world = doIO (\r
+       open "camil.txt" Lees >>=\r
+       \_ = open "mart.txt" Schrijf >>=\r
+       \_ = readline "camil.txt" >>=\r
+       \l = writeline (fromJust l) "mart.txt" >>=\r
+       \_ = close "camil.txt" >>=\r
+       \_ = close "mart.txt"\r
+       ) world\r
diff --git a/fp2/week2/mart/ToonFileMonad.icl b/fp2/week2/mart/ToonFileMonad.icl
deleted file mode 100644 (file)
index acd62c2..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-module ToonFileMonad\r
-\r
-import StdArray, StdInt, StdString     // expliciete imports van StdEnv om name-clash met StdFunc en StdIOMonad te voorkomen\r
-import StdIOMonad\r
-import StdMaybeMonad\r
-\r
-Start :: *World -> (Void,*World)\r
-Start world = doIO toon world\r
-\r
-toon :: IO Void\r
-toon = write "Voer een filenaam in: " >>= \_ ->\r
-       read                           >>= \filenaam ->\r
-       open (filenaam%(0,size filenaam-2)) Lees >>= \misschien_filehandle ->\r
-       case misschien_filehandle of\r
-           Nothing\r
-               = write ("Kon " +++ filenaam +++ " niet openen.\n") >>= \_ ->\r
-                 return Void\r
-           Just filehandle\r
-               = toon_inhoud filehandle\r
-\r
-toon_inhoud :: Filehandle -> IO Void\r
-toon_inhoud filehandle\r
-       = eof filehandle >>= \einde ->\r
-         if einde\r
-            (return Void)\r
-            (readline filehandle >>= \misschien_regel ->\r
-             case misschien_regel of\r
-                 Nothing    = return Void\r
-                 Just regel = write regel >>= \_ -> toon_inhoud filehandle\r
-            )\r
diff --git a/fp2/week2/mart/camil2.txt b/fp2/week2/mart/camil2.txt
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/fp2/week2/mart/oldold/old/Map.dcl b/fp2/week2/mart/oldold/old/Map.dcl
deleted file mode 100644 (file)
index 4848e1a..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-definition module Map\r
-\r
-//import BinTree\r
-import StdMaybe\r
-\r
-class Map c :: (a -> b) (c a) -> c b\r
-\r
-instance Map []\r
-instance Map Maybe\r
-//instance Map Tree\r
diff --git a/fp2/week2/mart/oldold/old/Map.icl b/fp2/week2/mart/oldold/old/Map.icl
deleted file mode 100644 (file)
index d248c66..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-implementation module Map\r
-\r
-//import BinTree\r
-import StdMaybe\r
-import StdList\r
-\r
-class Map c :: (a -> b) (c a) -> c b\r
-\r
-instance Map [] where \r
-       Map f [] = []\r
-       Map f [x:xs] = [f x: Map f xs]\r
-\r
-instance Map Maybe where\r
-       Map f Nothing = Nothing\r
-       Map f (Just x) = Just (f x)\r
-\r
-//instance Map Tree  where\r
-//     Map f Leaf = Leaf\r
-//     Map f (Node x l r) = Node (f x) (mapTree f l) (mapTree f r)\r
diff --git a/fp2/week2/mart/oldold/old/Mappen.icl b/fp2/week2/mart/oldold/old/Mappen.icl
deleted file mode 100644 (file)
index faca555..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-module Mappen\r
-\r
-import StdEnv\r
-import Map\r
-\r
-Start = (\r
-       Map ((+) 1) (Just 42), \r
-       Map ((+) 1) [1..10])\r
-//Map ((+) 1) t7)\r
diff --git a/fp2/week2/mart/oldold/old/Random.dcl b/fp2/week2/mart/oldold/old/Random.dcl
deleted file mode 100644 (file)
index 47a7c18..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-definition module Random
-
- // Random number generator voor Linux gebruikers
- // interface compatible met Random.dcl (helaas)
- // -- mschool@science.ru.nl
-
-import StdFile
-
-:: RandomSeed 
-
-// nullRandomSeed generates a fixed RandomSeed
-nullRandomSeed :: RandomSeed
-
-// GetNewRandomSeed generates a good RandomSeed, using /dev/urandom
-getNewRandomSeed :: !*env -> (!RandomSeed, !*env) | FileSystem env
-
-// Given a RandomSeed, Random generates a random number and a new RandomSeed.
-random :: !RandomSeed -> .(!Int, !RandomSeed)
-
diff --git a/fp2/week2/mart/oldold/old/Random.icl b/fp2/week2/mart/oldold/old/Random.icl
deleted file mode 100644 (file)
index b6e0768..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-implementation module Random
-
-import StdFile, StdList, StdMisc, StdArray, Random
-
-:: RandomSeed :== Int
-
-nullRandomSeed :: RandomSeed
-nullRandomSeed = 0
-
-getNewRandomSeed :: !*env -> (!RandomSeed, !*env) | FileSystem env
-getNewRandomSeed env
-# (ok, src, env) = sfopen "/dev/urandom" FReadData env
-| not ok => abort "could not open /dev/urandom"
-# (bytes, src)   = sfreads src 4
-  seed           = foldl (\x y->(x<<8)+toInt y) 0 [c \\ c<-:bytes]
-| otherwise => (seed, env)
-
-random :: !RandomSeed -> .(!Int, !RandomSeed)
-random seed = (seed>>16 bitand 0xFFFF, seed*0x08088405+1)
-
diff --git a/fp2/week2/mart/oldold/old/ReturnEnBind.icl b/fp2/week2/mart/oldold/old/ReturnEnBind.icl
deleted file mode 100644 (file)
index 6c3f8e4..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-module ReturnEnBind\r
-\r
-import StdEnv, Random\r
-\r
-Start = (r1, r2, r3, r4, nullRandomSeed, s1, s2, s3)\r
-       where\r
-               (r1, s1) = som2 nullRandomSeed\r
-               (r2, s2) = som2 s1\r
-               (r3, s3) = som2 s2\r
-               (r4, _) = som2 s3\r
-\r
-(bind1) infix 0 :: (St s a) (a -> (St s b)) -> St s b\r
-(bind1) f g = uncurry g o f\r
-\r
-som2 :: (RandomSeed -> (Int,RandomSeed))\r
-som2 = (\s -> random s) bind1 (\a -> random (snd a))\r
-\r
-seqList1 :: [St s a] -> St s [a]\r
-seqList1 ...\r
diff --git a/fp2/week2/mart/oldold/old/StdIOMonad.dcl b/fp2/week2/mart/oldold/old/StdIOMonad.dcl
deleted file mode 100644 (file)
index 375f077..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-definition module StdIOMonad\r
-\r
-//     Deze module verpakt een aantal StdFile functies in een monadische jas\r
-\r
-import StdMonad, StdMaybeMonad\r
-\r
-:: IO a\r
-:: Void       = Void\r
-:: Filemode   = Lees | Schrijf\r
-:: Filenaam :== String\r
-:: *Filehandle\r
-\r
-//     voer monadische I/O actie uit op de wereld:\r
-//doIO         :: (IO a) *World -> *(a,*World)\r
-\r
-//  IO is een monad:\r
-//instance return IO\r
-//instance >>=    IO\r
-\r
-//     lees regel van de console:\r
-read           :: IO String\r
-\r
-/*\r
-//     schrijf regel naar de console:\r
-write          :: String -> IO Void\r
-\r
-//     open de file met gegeven filenaam en mode:\r
-open           :: Filenaam Filemode -> IO (Maybe Filehandle)\r
-\r
-//     sluit de file met gegeven filenaam:\r
-close          :: Filehandle -> IO Bool\r
-\r
-//     bepaal of het lezen van de file klaar is:\r
-eof                    :: Filehandle -> IO Bool\r
-\r
-//     lees een regel van een file:\r
-readline       :: Filehandle -> IO (Maybe String)\r
-\r
-//     schrijf een regel naar een file:\r
-writeline      :: String Filehandle -> IO Bool*/\r
diff --git a/fp2/week2/mart/oldold/old/StdIOMonad.icl b/fp2/week2/mart/oldold/old/StdIOMonad.icl
deleted file mode 100644 (file)
index 0338a44..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-implementation module StdIOMonad\r
-\r
-//Deze module verpakt StdFile in een monadische jas\r
-\r
-import StdFile\r
-import StdMonad\r
-import StdMaybeMonad\r
-\r
-\r
-:: IO a = IO (*World Filehandle -> *(a, *World, Filehandle))\r
-:: Void       = Void\r
-:: Filemode   = Lees | Schrijf\r
-:: Filenaam :== String\r
-:: *Filehandle = None | FH *(Bool, Filemode, *File)\r
-\r
-toInt :: Filemode -> Int\r
-toInt Lees = FReadText\r
-toInt Schrijf = FWriteText\r
-\r
-Start world = read\r
-\r
-////voer monadische I/O actie uit op de wereld:\r
-//doIO :: (IO a) *World -> *(a,*World)\r
-//doIO (IO f) world = f (world, Closed)\r
-\r
-//  IO is een monad:\r
-instance return IO where\r
-       return x = IO (\w fh = (x, w, fh))\r
-//instance >>=    IO where\r
-//     (>>=) (IO f) g = IO(\w = let (a, w1) = f w in doIO (g a) w1)\r
-\r
-//lees regel van de console:\r
-read:: IO String\r
-read = IO (\w fh -> ("", w, fh))\r
-\r
-/*//schrijf regel naar de console:\r
-write:: String -> IO Void\r
-write s = IO (\w = (Void, write` s w))\r
-       where\r
-               write`:: String *World -> *World\r
-               write` s world\r
-               # (io, world) = stdio world\r
-               # io = fwrites s world\r
-               # (_, world) = fclose io\r
-               = world\r
-\r
-//open de file met gegeven filenaam en mode:\r
-open:: Filenaam Filemode -> IO (Maybe Filehandle)\r
-open s m = IO (\w = let (f1, w1) = openfh` s m w in (f1, (w1, f1)))\r
-       where\r
-               openfh`:: Filenaam Filemode *World -> (Maybe Filehandle, *World)\r
-               openfh` s m world\r
-               # (ok, file, world) = fopen s (toInt m) world\r
-               | ok = (Just (Open (m, file)), world)\r
-               | otherwise = (Nothing, world)\r
-\r
-//sluit de file met gegeven filenaam:\r
-close:: Filehandle -> IO Bool\r
-close fh = IO (\w = let (b1, w1) = close` fh w in (b1, (w1, Closed)))\r
-       where\r
-               close`:: Filehandle *World -> (Bool, *World)\r
-               close` Closed world = (False, world)\r
-               close` (Open (_, file)) world = fclose file world\r
-\r
-//bepaal of het lezen van de file klaar is:\r
-eof:: Filehandle -> IO Bool\r
-eof fh = IO (\w = let (b1, w1) = eof` fh w in (b1, (w1, Closed)))\r
-       where\r
-               eof`:: Filehandle *World -> (Bool, *World)\r
-               eof` Closed world = (world, False)\r
-               eaf`(Open (_, file)) world = fclose file\r
-\r
-//lees een regel van een file:\r
-readline:: Filehandle -> IO (Maybe String)\r
-readline fh = IO (\w = let r1 = readline` fh w in r1)\r
-       where\r
-               readline`:: Filehandle *World -> (Maybe String, (*World, Filehandle))\r
-               readline` Closed world = (world, Nothing)\r
-               readline` (Open (Schrijf, _)) world = (world, Nothing)\r
-               readline` (Open (Lees, file)) world\r
-               # (line, file) = sfreadline file\r
-               = (Just line, (world, Open (Lees, file)))\r
-\r
-//schrijf een regel naar een file:\r
-writeline:: String Filehandle -> IO Bool\r
-writeline s fh = IO (\w = let r1 = writeline` s fh w in r1)\r
-       where\r
-               writeline`:: String Filehandle *World -> (Bool, (*World, Filehandle))\r
-               writeline` line Closed world = (False, (world, Closed))\r
-               writeline` line (Open (Lees, file)) world = (False, (world, (Open (Lees, file))))\r
-               writeline` line (Open (Schrijf, file)) world\r
-               # file = fwrites line file\r
-               = (True, (world, file))*/\r
diff --git a/fp2/week2/mart/oldold/old/StdMaybeMonad.dcl b/fp2/week2/mart/oldold/old/StdMaybeMonad.dcl
deleted file mode 100644 (file)
index e9ebec1..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-definition module StdMaybeMonad\r
-\r
-import StdMonad\r
-\r
-:: Maybe a = Nothing | Just a\r
-\r
-instance return        Maybe\r
-instance >>=   Maybe\r
-instance fail   Maybe\r
diff --git a/fp2/week2/mart/oldold/old/StdMaybeMonad.icl b/fp2/week2/mart/oldold/old/StdMaybeMonad.icl
deleted file mode 100644 (file)
index 1c6277d..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-implementation module StdMaybeMonad\r
-\r
-import StdMonad\r
-\r
-:: Maybe a = Nothing | Just a\r
-\r
-instance return        Maybe where return x       = Just x\r
-instance >>=   Maybe where >>= (Just x) f = f x\r
-                            >>= Nothing  f = Nothing\r
-instance fail   Maybe where fail           = Nothing\r
diff --git a/fp2/week2/mart/oldold/old/StdMonad.dcl b/fp2/week2/mart/oldold/old/StdMonad.dcl
deleted file mode 100644 (file)
index cd1c654..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-definition module StdMonad\r
-\r
-class return        c :: a -> c a\r
-class (>>=) infix 0    c :: (c a) (a -> c b) -> c b\r
-class fail          c :: c a\r
-\r
-class Monad            c | return, >>= c\r
-class MonadFail            c | Monad, fail c\r
diff --git a/fp2/week2/mart/oldold/old/StdMonad.icl b/fp2/week2/mart/oldold/old/StdMonad.icl
deleted file mode 100644 (file)
index db193ab..0000000
+++ /dev/null
@@ -1 +0,0 @@
-implementation module StdMonad\r
diff --git a/fp2/week2/mart/s4109503_s4498062_fp2_w2.tar.gz b/fp2/week2/mart/s4109503_s4498062_fp2_w2.tar.gz
new file mode 100644 (file)
index 0000000..587d742
Binary files /dev/null and b/fp2/week2/mart/s4109503_s4498062_fp2_w2.tar.gz differ