From: Ramakrishnan Muthukrishnan Date: Wed, 24 Dec 2014 14:24:10 +0000 (+0530) Subject: hw7: exercise 1 X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/biz/offer/smbiz.html?a=commitdiff_plain;h=112ab0cf035304d521aaf51dea1c021f7e2d2c46;p=yorgey.git hw7: exercise 1 --- diff --git a/hw7/JoinList.hs b/hw7/JoinList.hs new file mode 100644 index 0000000..4edc744 --- /dev/null +++ b/hw7/JoinList.hs @@ -0,0 +1,22 @@ +{-# OPTIONS_GHC -Wall #-} +module JoinList where + +import Data.Monoid + + +data JoinList m a = Empty + | Single m a + | Append m (JoinList m a) (JoinList m a) + deriving (Eq, Show) + +-- exercise 1 +tag :: Monoid m => JoinList m a -> m +tag (Empty) = mempty +tag (Single t _) = t +tag (Append t _ _) = t + +(+++) :: Monoid m => JoinList m a -> JoinList m a -> JoinList m a +Empty +++ x = x +x +++ Empty = x +alst1 +++ alst2 = Append ((tag alst1) `mappend` (tag alst2)) alst1 alst2 +