| 1 | {-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, OverlappingInstances, UndecidableInstances #-} |
|---|
| 2 | module Main where |
|---|
| 3 | |
|---|
| 4 | import Control.Monad.Trans (MonadIO(..)) |
|---|
| 5 | |
|---|
| 6 | class XMLGenerator m where |
|---|
| 7 | genElement :: (Maybe String, String) -> m () |
|---|
| 8 | |
|---|
| 9 | newtype IdentityT m a = IdentityT { runIdentityT :: m a } |
|---|
| 10 | deriving (Monad, MonadIO) |
|---|
| 11 | |
|---|
| 12 | instance (MonadIO m) => (XMLGenerator (IdentityT m)) where |
|---|
| 13 | genElement _ = liftIO $ putStrLn "in genElement" |
|---|
| 14 | |
|---|
| 15 | main :: IO () |
|---|
| 16 | main = |
|---|
| 17 | do runIdentityT web |
|---|
| 18 | putStrLn "done." |
|---|
| 19 | |
|---|
| 20 | class (Widgets x) => MonadRender x |
|---|
| 21 | class (XMLGenerator m) => Widgets m |
|---|
| 22 | -- instance Widgets (IdentityT IO) -- if you uncomment this, it will work |
|---|
| 23 | instance MonadRender m => Widgets m |
|---|
| 24 | instance MonadRender (IdentityT IO) |
|---|
| 25 | |
|---|
| 26 | web :: ( MonadIO m |
|---|
| 27 | , Widgets m |
|---|
| 28 | , XMLGenerator m |
|---|
| 29 | ) => m () |
|---|
| 30 | web = |
|---|
| 31 | do liftIO $ putStrLn "before" |
|---|
| 32 | genElement (Nothing, "p") |
|---|
| 33 | return () |
|---|