fork(1) download
  1. import Control.Applicative
  2.  
  3. data MyCoolIO a = MCIO (IO a)
  4.  
  5. instance Functor MyCoolIO where
  6. fmap f (MCIO xIO) = MCIO $ fmap f xIO
  7.  
  8. instance Applicative MyCoolIO where
  9. pure = MCIO . pure
  10. (MCIO fIO) <*> (MCIO xIO) = MCIO $ fIO <*> xIO
  11.  
  12. instance Monad MyCoolIO where
  13. return = pure
  14.  
  15. (MCIO xIO) >>= f = MCIO $ xIO >>= \x -> (let (MCIO r) = f x in r)
  16. (MCIO xIO) >> (MCIO yIO) = MCIO $ yIO >>= \y -> (xIO >> return y)
  17.  
  18. myPutStrLn :: String -> MyCoolIO ()
  19. myPutStrLn s = MCIO $ putStrLn s
  20.  
  21. myMain :: MyCoolIO () -> IO ()
  22. myMain (MCIO io) = io
  23.  
  24. main = myMain $ do
  25. myPutStrLn "first"
  26. myPutStrLn "second"
  27. myPutStrLn "third"
  28.  
Success #stdin #stdout 0s 5448KB
stdin
Standard input is empty
stdout
third
second
first