f620d8fb63ab5670b95a1068144a1f0c079b6621
[ghc.git] / testsuite / tests / typecheck / should_run / T5751.hs
1 {-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, OverlappingInstances, UndecidableInstances #-}
2 module Main where
3
4 class (Monad m) => MonadIO m where
5 -- | Lift a computation from the 'IO' monad.
6 liftIO :: IO a -> m a
7
8 instance MonadIO IO where
9 liftIO = id
10
11 class XMLGenerator m where
12 genElement :: (Maybe String, String) -> m ()
13
14 newtype IdentityT m a = IdentityT { runIdentityT :: m a }
15 deriving (Monad, MonadIO)
16
17 instance (MonadIO m) => (XMLGenerator (IdentityT m)) where
18 genElement _ = liftIO $ putStrLn "in genElement"
19
20 main :: IO ()
21 main =
22 do runIdentityT web
23 putStrLn "done."
24
25 class (Widgets x) => MonadRender x
26 class (XMLGenerator m) => Widgets m
27 -- instance Widgets (IdentityT IO) -- if you uncomment this, it will work
28 instance MonadRender m => Widgets m
29 instance MonadRender (IdentityT IO)
30
31 web :: ( MonadIO m
32 , Widgets m
33 , XMLGenerator m
34 ) => m ()
35 web =
36 do liftIO $ putStrLn "before"
37 genElement (Nothing, "p")
38 return ()