CK Kashyap ck_kashyap at yahoo.com
Tue Dec 29 01:58:32 EST 2009

```Hi,
understand it. In my attempt to validate my understanding, I've written my version of List data structure with Monadic behaviour -
I'd appreciate answers to the following queries -
2. I've used the do notation at the bottom which is a result of my List being a Monad - are there any other benefits that comes in because of List being a Monad? What would MonadPlus provide me?
3. The comprehension syntax for Lists in Haskell - can that be used in anyway for other Monads?

Regards,
Kashyap

data List a = Cons a (List a) | Empty
deriving Show

--myMap :: (t -> a) -> List t -> List a
myMap :: (t -> a) -> List t -> List a
myMap f Empty = Empty
myMap f (Cons a rest) = Cons (f a) (myMap f rest)

--myAppend :: List a -> List a -> List a
myAppend :: List a -> List a -> List a
myAppend Empty l = l
myAppend l Empty = l
myAppend (Cons a rest) l = Cons a (myAppend rest l)

--myConcat :: List (List a) -> List a
myConcat :: List (List a) -> List a
myConcat Empty= Empty
myConcat (Cons Empty rest)= myConcat rest
myConcat (Cons list rest)= myAppend list (myConcat rest)

return a = Cons a Empty
Empty >>= f = Empty
l >>= f = myConcat (myMap f l)

p `mplus` q = myAppend p q
mzero= Empty

list2myList :: [a] -> List a
list2myList [] = Empty
list2myList (x:xs) = Cons x (list2myList xs)

l1 =  list2myList [1..10]
l2 = do
x <- l1
y <- Cons (2*x) Empty
return y

```