From a067356625105f50978443d3b0a0a5d8f6391184 Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Fri, 24 Apr 2015 14:35:17 +0200 Subject: rare shit --- fp2/week2/mart/EchoMonad.icl | 14 +++++ fp2/week2/mart/Map.dcl | 10 ---- fp2/week2/mart/Map.icl | 19 ------ fp2/week2/mart/Mappen.icl | 9 --- fp2/week2/mart/Random.dcl | 19 ------ fp2/week2/mart/Random.icl | 20 ------- fp2/week2/mart/ReturnEnBind.icl | 19 ------ fp2/week2/mart/StdIOMonad.dcl | 39 ++++++++++++ fp2/week2/mart/StdIOMonad.icl | 38 +++++------- fp2/week2/mart/StdListMonad.dcl | 7 +++ fp2/week2/mart/StdListMonad.icl | 7 +++ fp2/week2/mart/StdMaybeMonad.dcl | 9 +++ fp2/week2/mart/StdMaybeMonad.icl | 10 ++++ fp2/week2/mart/ToonFileMonad.icl | 30 ++++++++++ fp2/week2/mart/oldold/old/Map.dcl | 10 ++++ fp2/week2/mart/oldold/old/Map.icl | 19 ++++++ fp2/week2/mart/oldold/old/Mappen.icl | 9 +++ fp2/week2/mart/oldold/old/Random.dcl | 19 ++++++ fp2/week2/mart/oldold/old/Random.icl | 20 +++++++ fp2/week2/mart/oldold/old/ReturnEnBind.icl | 19 ++++++ fp2/week2/mart/oldold/old/StdIOMonad.dcl | 40 +++++++++++++ fp2/week2/mart/oldold/old/StdIOMonad.icl | 93 +++++++++++++++++++++++++++++ fp2/week2/mart/oldold/old/StdMaybeMonad.dcl | 9 +++ fp2/week2/mart/oldold/old/StdMaybeMonad.icl | 10 ++++ fp2/week2/mart/oldold/old/StdMonad.dcl | 8 +++ fp2/week2/mart/oldold/old/StdMonad.icl | 1 + 26 files changed, 389 insertions(+), 118 deletions(-) create mode 100644 fp2/week2/mart/EchoMonad.icl delete mode 100644 fp2/week2/mart/Map.dcl delete mode 100644 fp2/week2/mart/Map.icl delete mode 100644 fp2/week2/mart/Mappen.icl delete mode 100644 fp2/week2/mart/Random.dcl delete mode 100644 fp2/week2/mart/Random.icl delete mode 100644 fp2/week2/mart/ReturnEnBind.icl create mode 100644 fp2/week2/mart/StdIOMonad.dcl create mode 100644 fp2/week2/mart/StdListMonad.dcl create mode 100644 fp2/week2/mart/StdListMonad.icl create mode 100644 fp2/week2/mart/StdMaybeMonad.dcl create mode 100644 fp2/week2/mart/StdMaybeMonad.icl create mode 100644 fp2/week2/mart/ToonFileMonad.icl create mode 100644 fp2/week2/mart/oldold/old/Map.dcl create mode 100644 fp2/week2/mart/oldold/old/Map.icl create mode 100644 fp2/week2/mart/oldold/old/Mappen.icl create mode 100644 fp2/week2/mart/oldold/old/Random.dcl create mode 100644 fp2/week2/mart/oldold/old/Random.icl create mode 100644 fp2/week2/mart/oldold/old/ReturnEnBind.icl create mode 100644 fp2/week2/mart/oldold/old/StdIOMonad.dcl create mode 100644 fp2/week2/mart/oldold/old/StdIOMonad.icl create mode 100644 fp2/week2/mart/oldold/old/StdMaybeMonad.dcl create mode 100644 fp2/week2/mart/oldold/old/StdMaybeMonad.icl create mode 100644 fp2/week2/mart/oldold/old/StdMonad.dcl create mode 100644 fp2/week2/mart/oldold/old/StdMonad.icl (limited to 'fp2/week2/mart') diff --git a/fp2/week2/mart/EchoMonad.icl b/fp2/week2/mart/EchoMonad.icl new file mode 100644 index 0000000..3bcab11 --- /dev/null +++ b/fp2/week2/mart/EchoMonad.icl @@ -0,0 +1,14 @@ +module EchoMonad + +import StdString // expliciete import uit StdEnv om nameclash met StdFunc / StdIOMonad te voorkomen +import StdIOMonad +import StdMaybeMonad + +Start :: *World -> (Void,*World) +Start world = doIO echo world + +echo :: IO Void +echo = read >>= \regel -> + if (regel == "\n") + (return Void) + (write regel >>= \_ -> echo) diff --git a/fp2/week2/mart/Map.dcl b/fp2/week2/mart/Map.dcl deleted file mode 100644 index 4848e1a..0000000 --- a/fp2/week2/mart/Map.dcl +++ /dev/null @@ -1,10 +0,0 @@ -definition module Map - -//import BinTree -import StdMaybe - -class Map c :: (a -> b) (c a) -> c b - -instance Map [] -instance Map Maybe -//instance Map Tree diff --git a/fp2/week2/mart/Map.icl b/fp2/week2/mart/Map.icl deleted file mode 100644 index d248c66..0000000 --- a/fp2/week2/mart/Map.icl +++ /dev/null @@ -1,19 +0,0 @@ -implementation module Map - -//import BinTree -import StdMaybe -import StdList - -class Map c :: (a -> b) (c a) -> c b - -instance Map [] where - Map f [] = [] - Map f [x:xs] = [f x: Map f xs] - -instance Map Maybe where - Map f Nothing = Nothing - Map f (Just x) = Just (f x) - -//instance Map Tree where -// Map f Leaf = Leaf -// Map f (Node x l r) = Node (f x) (mapTree f l) (mapTree f r) diff --git a/fp2/week2/mart/Mappen.icl b/fp2/week2/mart/Mappen.icl deleted file mode 100644 index faca555..0000000 --- a/fp2/week2/mart/Mappen.icl +++ /dev/null @@ -1,9 +0,0 @@ -module Mappen - -import StdEnv -import Map - -Start = ( - Map ((+) 1) (Just 42), - Map ((+) 1) [1..10]) -//Map ((+) 1) t7) diff --git a/fp2/week2/mart/Random.dcl b/fp2/week2/mart/Random.dcl deleted file mode 100644 index 47a7c18..0000000 --- a/fp2/week2/mart/Random.dcl +++ /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/Random.icl b/fp2/week2/mart/Random.icl deleted file mode 100644 index b6e0768..0000000 --- a/fp2/week2/mart/Random.icl +++ /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/ReturnEnBind.icl b/fp2/week2/mart/ReturnEnBind.icl deleted file mode 100644 index 6c3f8e4..0000000 --- a/fp2/week2/mart/ReturnEnBind.icl +++ /dev/null @@ -1,19 +0,0 @@ -module ReturnEnBind - -import StdEnv, Random - -Start = (r1, r2, r3, r4, nullRandomSeed, s1, s2, s3) - where - (r1, s1) = som2 nullRandomSeed - (r2, s2) = som2 s1 - (r3, s3) = som2 s2 - (r4, _) = som2 s3 - -(bind1) infix 0 :: (St s a) (a -> (St s b)) -> St s b -(bind1) f g = uncurry g o f - -som2 :: (RandomSeed -> (Int,RandomSeed)) -som2 = (\s -> random s) bind1 (\a -> random (snd a)) - -seqList1 :: [St s a] -> St s [a] -seqList1 ... diff --git a/fp2/week2/mart/StdIOMonad.dcl b/fp2/week2/mart/StdIOMonad.dcl new file mode 100644 index 0000000..0d451d2 --- /dev/null +++ b/fp2/week2/mart/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/fp2/week2/mart/StdIOMonad.icl b/fp2/week2/mart/StdIOMonad.icl index 7f112a7..1d4b24e 100644 --- a/fp2/week2/mart/StdIOMonad.icl +++ b/fp2/week2/mart/StdIOMonad.icl @@ -1,22 +1,16 @@ -module StdIOMonad - -import StdEnv, StdMaybe, StdMonad, StdFile - -:: IO a = IO (*World -> *(a, *World)) - -read :: *World -> (IO String, *World) -read world -# (io, world) = stdio world -# (line, io) = freadline io -# (ok, world) = fclose io -| not ok = abort "Couldn't close console" -| otherwise = line - -instance return IO where - return x = IO (\w = (x, w)) - -instance >>= IO where - >>= (IO f) g = (IO f) - -Start :: *World -> (IO String, *World) -Start world = read +implementation module StdIOMonad + +// Deze module verpakt StdFile in een monadische jas + +import StdFile +import StdMonad +//import StdOverloaded + +:: IO a = 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/fp2/week2/mart/StdListMonad.dcl b/fp2/week2/mart/StdListMonad.dcl new file mode 100644 index 0000000..576ef55 --- /dev/null +++ b/fp2/week2/mart/StdListMonad.dcl @@ -0,0 +1,7 @@ +definition module StdListMonad + +import StdMonad + +instance return [] +instance >>= [] +instance fail [] diff --git a/fp2/week2/mart/StdListMonad.icl b/fp2/week2/mart/StdListMonad.icl new file mode 100644 index 0000000..b3b3d62 --- /dev/null +++ b/fp2/week2/mart/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/fp2/week2/mart/StdMaybeMonad.dcl b/fp2/week2/mart/StdMaybeMonad.dcl new file mode 100644 index 0000000..e9ebec1 --- /dev/null +++ b/fp2/week2/mart/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/fp2/week2/mart/StdMaybeMonad.icl b/fp2/week2/mart/StdMaybeMonad.icl new file mode 100644 index 0000000..1c6277d --- /dev/null +++ b/fp2/week2/mart/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/fp2/week2/mart/ToonFileMonad.icl b/fp2/week2/mart/ToonFileMonad.icl new file mode 100644 index 0000000..acd62c2 --- /dev/null +++ b/fp2/week2/mart/ToonFileMonad.icl @@ -0,0 +1,30 @@ +module ToonFileMonad + +import StdArray, StdInt, StdString // expliciete imports van StdEnv om name-clash met StdFunc en StdIOMonad te voorkomen +import StdIOMonad +import StdMaybeMonad + +Start :: *World -> (Void,*World) +Start world = doIO toon world + +toon :: IO Void +toon = write "Voer een filenaam in: " >>= \_ -> + read >>= \filenaam -> + open (filenaam%(0,size filenaam-2)) Lees >>= \misschien_filehandle -> + case misschien_filehandle of + Nothing + = write ("Kon " +++ filenaam +++ " niet openen.\n") >>= \_ -> + return Void + Just filehandle + = toon_inhoud filehandle + +toon_inhoud :: Filehandle -> IO Void +toon_inhoud filehandle + = eof filehandle >>= \einde -> + if einde + (return Void) + (readline filehandle >>= \misschien_regel -> + case misschien_regel of + Nothing = return Void + Just regel = write regel >>= \_ -> toon_inhoud filehandle + ) diff --git a/fp2/week2/mart/oldold/old/Map.dcl b/fp2/week2/mart/oldold/old/Map.dcl new file mode 100644 index 0000000..4848e1a --- /dev/null +++ b/fp2/week2/mart/oldold/old/Map.dcl @@ -0,0 +1,10 @@ +definition module Map + +//import BinTree +import StdMaybe + +class Map c :: (a -> b) (c a) -> c b + +instance Map [] +instance Map Maybe +//instance Map Tree diff --git a/fp2/week2/mart/oldold/old/Map.icl b/fp2/week2/mart/oldold/old/Map.icl new file mode 100644 index 0000000..d248c66 --- /dev/null +++ b/fp2/week2/mart/oldold/old/Map.icl @@ -0,0 +1,19 @@ +implementation module Map + +//import BinTree +import StdMaybe +import StdList + +class Map c :: (a -> b) (c a) -> c b + +instance Map [] where + Map f [] = [] + Map f [x:xs] = [f x: Map f xs] + +instance Map Maybe where + Map f Nothing = Nothing + Map f (Just x) = Just (f x) + +//instance Map Tree where +// Map f Leaf = Leaf +// Map f (Node x l r) = Node (f x) (mapTree f l) (mapTree f r) diff --git a/fp2/week2/mart/oldold/old/Mappen.icl b/fp2/week2/mart/oldold/old/Mappen.icl new file mode 100644 index 0000000..faca555 --- /dev/null +++ b/fp2/week2/mart/oldold/old/Mappen.icl @@ -0,0 +1,9 @@ +module Mappen + +import StdEnv +import Map + +Start = ( + Map ((+) 1) (Just 42), + Map ((+) 1) [1..10]) +//Map ((+) 1) t7) diff --git a/fp2/week2/mart/oldold/old/Random.dcl b/fp2/week2/mart/oldold/old/Random.dcl new file mode 100644 index 0000000..47a7c18 --- /dev/null +++ b/fp2/week2/mart/oldold/old/Random.dcl @@ -0,0 +1,19 @@ +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 new file mode 100644 index 0000000..b6e0768 --- /dev/null +++ b/fp2/week2/mart/oldold/old/Random.icl @@ -0,0 +1,20 @@ +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 new file mode 100644 index 0000000..6c3f8e4 --- /dev/null +++ b/fp2/week2/mart/oldold/old/ReturnEnBind.icl @@ -0,0 +1,19 @@ +module ReturnEnBind + +import StdEnv, Random + +Start = (r1, r2, r3, r4, nullRandomSeed, s1, s2, s3) + where + (r1, s1) = som2 nullRandomSeed + (r2, s2) = som2 s1 + (r3, s3) = som2 s2 + (r4, _) = som2 s3 + +(bind1) infix 0 :: (St s a) (a -> (St s b)) -> St s b +(bind1) f g = uncurry g o f + +som2 :: (RandomSeed -> (Int,RandomSeed)) +som2 = (\s -> random s) bind1 (\a -> random (snd a)) + +seqList1 :: [St s a] -> St s [a] +seqList1 ... diff --git a/fp2/week2/mart/oldold/old/StdIOMonad.dcl b/fp2/week2/mart/oldold/old/StdIOMonad.dcl new file mode 100644 index 0000000..375f077 --- /dev/null +++ b/fp2/week2/mart/oldold/old/StdIOMonad.dcl @@ -0,0 +1,40 @@ +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/fp2/week2/mart/oldold/old/StdIOMonad.icl b/fp2/week2/mart/oldold/old/StdIOMonad.icl new file mode 100644 index 0000000..0338a44 --- /dev/null +++ b/fp2/week2/mart/oldold/old/StdIOMonad.icl @@ -0,0 +1,93 @@ +implementation module StdIOMonad + +//Deze module verpakt StdFile in een monadische jas + +import StdFile +import StdMonad +import StdMaybeMonad + + +:: IO a = IO (*World Filehandle -> *(a, *World, Filehandle)) +:: Void = Void +:: Filemode = Lees | Schrijf +:: Filenaam :== String +:: *Filehandle = None | FH *(Bool, Filemode, *File) + +toInt :: Filemode -> Int +toInt Lees = FReadText +toInt Schrijf = FWriteText + +Start world = read + +////voer monadische I/O actie uit op de wereld: +//doIO :: (IO a) *World -> *(a,*World) +//doIO (IO f) world = f (world, Closed) + +// IO is een monad: +instance return IO where + return x = IO (\w fh = (x, w, fh)) +//instance >>= IO where +// (>>=) (IO f) g = IO(\w = let (a, w1) = f w in doIO (g a) w1) + +//lees regel van de console: +read:: IO String +read = IO (\w fh -> ("", w, fh)) + +/*//schrijf regel naar de console: +write:: String -> IO Void +write s = IO (\w = (Void, write` s w)) + where + write`:: String *World -> *World + write` s world + # (io, world) = stdio world + # io = fwrites s world + # (_, world) = fclose io + = world + +//open de file met gegeven filenaam en mode: +open:: Filenaam Filemode -> IO (Maybe Filehandle) +open s m = IO (\w = let (f1, w1) = openfh` s m w in (f1, (w1, f1))) + where + openfh`:: Filenaam Filemode *World -> (Maybe Filehandle, *World) + openfh` s m world + # (ok, file, world) = fopen s (toInt m) world + | ok = (Just (Open (m, file)), world) + | otherwise = (Nothing, world) + +//sluit de file met gegeven filenaam: +close:: Filehandle -> IO Bool +close fh = IO (\w = let (b1, w1) = close` fh w in (b1, (w1, Closed))) + where + close`:: Filehandle *World -> (Bool, *World) + close` Closed world = (False, world) + close` (Open (_, file)) world = fclose file world + +//bepaal of het lezen van de file klaar is: +eof:: Filehandle -> IO Bool +eof fh = IO (\w = let (b1, w1) = eof` fh w in (b1, (w1, Closed))) + where + eof`:: Filehandle *World -> (Bool, *World) + eof` Closed world = (world, False) + eaf`(Open (_, file)) world = fclose file + +//lees een regel van een file: +readline:: Filehandle -> IO (Maybe String) +readline fh = IO (\w = let r1 = readline` fh w in r1) + where + readline`:: Filehandle *World -> (Maybe String, (*World, Filehandle)) + readline` Closed world = (world, Nothing) + readline` (Open (Schrijf, _)) world = (world, Nothing) + readline` (Open (Lees, file)) world + # (line, file) = sfreadline file + = (Just line, (world, Open (Lees, file))) + +//schrijf een regel naar een file: +writeline:: String Filehandle -> IO Bool +writeline s fh = IO (\w = let r1 = writeline` s fh w in r1) + where + writeline`:: String Filehandle *World -> (Bool, (*World, Filehandle)) + writeline` line Closed world = (False, (world, Closed)) + writeline` line (Open (Lees, file)) world = (False, (world, (Open (Lees, file)))) + writeline` line (Open (Schrijf, file)) world + # file = fwrites line file + = (True, (world, file))*/ diff --git a/fp2/week2/mart/oldold/old/StdMaybeMonad.dcl b/fp2/week2/mart/oldold/old/StdMaybeMonad.dcl new file mode 100644 index 0000000..e9ebec1 --- /dev/null +++ b/fp2/week2/mart/oldold/old/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/fp2/week2/mart/oldold/old/StdMaybeMonad.icl b/fp2/week2/mart/oldold/old/StdMaybeMonad.icl new file mode 100644 index 0000000..1c6277d --- /dev/null +++ b/fp2/week2/mart/oldold/old/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/fp2/week2/mart/oldold/old/StdMonad.dcl b/fp2/week2/mart/oldold/old/StdMonad.dcl new file mode 100644 index 0000000..cd1c654 --- /dev/null +++ b/fp2/week2/mart/oldold/old/StdMonad.dcl @@ -0,0 +1,8 @@ +definition module StdMonad + +class return c :: a -> c a +class (>>=) infix 0 c :: (c a) (a -> c b) -> c b +class fail c :: c a + +class Monad c | return, >>= c +class MonadFail c | Monad, fail c diff --git a/fp2/week2/mart/oldold/old/StdMonad.icl b/fp2/week2/mart/oldold/old/StdMonad.icl new file mode 100644 index 0000000..db193ab --- /dev/null +++ b/fp2/week2/mart/oldold/old/StdMonad.icl @@ -0,0 +1 @@ +implementation module StdMonad -- cgit v1.2.3