view src/list_monad.hs @ 26:de3397af1f8d

Temporary save
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Tue, 10 Feb 2015 15:30:01 +0900
parents fc44782929a7
children
line wrap: on
line source

append :: List a -> List a -> List a
append Nil xs          = xs
append (Cons x xs) xss = Cons x (append xs xss)

concat :: List (List a) -> List a
concat Nil         = Nil
concat (Cons x xs) = append x (Main.concat xs)

eta :: a -> List a
eta x = Cons x Nil

mu :: List (List a) -> List a
mu = Main.concat

instance Monad List where
    return x  = eta x
    li >>= f  = mu (fmap f li)