thrist-0.4: Data/Thrist/List.hs
module Data.Thrist.List ( List(..) ) where
import Data.Thrist
import Control.Monad ()
import Control.Applicative (Applicative(..))
-- Adapter for creating lists:
-- (Thrist List a a) is isomorphic to [a]
data List :: * -> * -> * where
El :: a -> List a a
-- It forms a monad
--
newtype List' a = List' (Thrist List a a)
instance Functor List' where
fmap _ (List' Nil) = List' Nil
fmap f (List' (Cons (El a) as)) = List' $ Cons (El $ f a) (unlist' . fmap f $ List' as)
where unlist' (List' l) = l
instance Applicative List' where
pure = return
(<*>) = undefined -- TODO
instance Monad List' where
return a = List' $ Cons (El a) Nil
List' a >>= f = undefined -- TODO
{- We need something like:
instance Monad [] where
m >>= k = foldr ((++) . k) [] m
m >> k = foldr ((++) . (\ _ -> k)) [] m
return x = [x]
fail _ = []
-}