From 1dfba10f79adc5fc3a79f307beb514e53945df6e Mon Sep 17 00:00:00 2001 From: milad Date: Tue, 27 Dec 2016 12:39:19 +0330 Subject: [PATCH] finished exercises on Course.Extend --- README.markdown | 2 +- src/Course/Extend.hs | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.markdown b/README.markdown index b6b9f80..969bb8c 100644 --- a/README.markdown +++ b/README.markdown @@ -26,7 +26,7 @@ After this, the following progression of modules is recommended: * `Course.FileIO` -> Done * `Course.State` -> Done * `Course.StateT` -> Done -* `Course.Extend` +* `Course.Extend` -> Done * `Course.Comonad` * `Course.Compose` * `Course.Traversable` diff --git a/src/Course/Extend.hs b/src/Course/Extend.hs index 80295b8..edd7dff 100644 --- a/src/Course/Extend.hs +++ b/src/Course/Extend.hs @@ -33,8 +33,7 @@ instance Extend Id where (Id a -> b) -> Id a -> Id b - (<<=) = - error "todo: Course.Extend (<<=)#instance Id" + (<<=) f ida = Id $ f ida -- | Implement the @Extend@ instance for @List@. -- @@ -51,8 +50,8 @@ instance Extend List where (List a -> b) -> List a -> List b - (<<=) = - error "todo: Course.Extend (<<=)#instance List" + (<<=) _ Nil = Nil + (<<=) fla la@(_:.res) = fla la :. (<<=) fla res -- | Implement the @Extend@ instance for @Optional@. -- @@ -66,8 +65,8 @@ instance Extend Optional where (Optional a -> b) -> Optional a -> Optional b - (<<=) = - error "todo: Course.Extend (<<=)#instance Optional" + (<<=) _ Empty = Empty + (<<=) f a = Full (f a) -- | Duplicate the functor using extension. -- @@ -86,5 +85,4 @@ cojoin :: Extend f => f a -> f (f a) -cojoin = - error "todo: Course.Extend#cojoin" +cojoin fa = id <<= fa