diff --git a/src/Monad/Functor.hs b/src/Monad/Functor.hs index 0ec50baa8..fc11596d6 100644 --- a/src/Monad/Functor.hs +++ b/src/Monad/Functor.hs @@ -62,20 +62,17 @@ instance Functor ((->) t) where fmap = error "todo" --- Exercise 5 --- Relative Difficulty: 2 --- +----------------------- +-- SUPPORT LIBRARIES -- +----------------------- + -- | Maps a function on an IO program. -- -- >>> fmap reverse (putStr "hi" >> return "abc") -- hi"cba" instance Functor IO where fmap = - error "todo" - ------------------------ --- SUPPORT LIBRARIES -- ------------------------ + P.fmap instance Functor [] where fmap = diff --git a/src/Monad/Monad.hs b/src/Monad/Monad.hs index 4a854a9ab..9a1e0ade8 100644 --- a/src/Monad/Monad.hs +++ b/src/Monad/Monad.hs @@ -101,18 +101,6 @@ instance Monad ((->) t) where -- Exercise 11 -- Relative Difficulty: 2 -- --- | Instance the monad type-class for IO. --- --- /Tip:/ Use standard library functions. This is not cheating. -instance Monad IO where - bind = - error "todo" - return = - error "todo" - --- Exercise 12 --- Relative Difficulty: 2 --- -- | Flattens a combined structure to a single structure. -- -- >>> flaatten ((1 :. 2 :. 3 :. Nil) :. (1 :. 2 :. Nil) :. Nil) @@ -133,7 +121,7 @@ flaatten :: flaatten = error "todo" --- Exercise 13 +-- Exercise 12 -- Relative Difficulty: 10 -- -- | Applies a structure on functions to a structure on values. @@ -166,7 +154,7 @@ apply :: apply = error "todo" --- Exercise 14 +-- Exercise 13 -- Relative Difficulty: 6 -- (bonus: use apply + fmap') -- @@ -198,7 +186,7 @@ lift2 :: lift2 = error "todo" --- Exercise 15 +-- Exercise 14 -- Relative Difficulty: 6 -- (bonus: use apply + lift2) -- @@ -234,7 +222,7 @@ lift3 :: lift3 = error "todo" --- Exercise 16 +-- Exercise 15 -- Relative Difficulty: 6 -- (bonus: use apply + lift3) -- @@ -271,7 +259,7 @@ lift4 :: lift4 = error "todo" --- Exercise 17 +-- Exercise 16 -- Relative Difficulty: 3 -- -- | Sequences a list of structures to a structure of list. @@ -297,7 +285,7 @@ seequence :: seequence = error "todo" --- Exercise 18 +-- Exercise 17 -- Relative Difficulty: 3 -- -- | Traverse (map) a list of values with an effect. @@ -324,7 +312,7 @@ traaverse :: traaverse = error "todo" --- Exercise 19 +-- Exercise 18 -- Relative Difficulty: 4 -- -- | Replicate an effect a given number of times. @@ -348,7 +336,7 @@ reeplicate :: reeplicate = error "todo" --- Exercise 20 +-- Exercise 19 -- Relative Difficulty: 9 -- -- | Filter a list with a predicate that produces an effect. @@ -379,6 +367,12 @@ filtering = -- SUPPORT LIBRARIES -- ----------------------- +instance Monad IO where + bind = + (=<<) + return = + P.return + instance Monad [] where bind = (P.=<<) return = P.return