Tc239_Help.hs 502 Bytes
Newer Older
thoughtpolice's avatar
thoughtpolice committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
module Tc239_Help ( WrapIO, WrapIO2 ) where

import Control.Applicative (Applicative(..))
import Control.Monad (liftM, ap)

newtype WrapIO e a = MkWrapIO { unwrap :: IO a }

type WrapIO2 a = WrapIO String a

instance Functor (WrapIO e) where
    fmap = liftM

instance Applicative (WrapIO e) where
    pure = return
    (<*>) = ap

instance Monad (WrapIO e) where
  return x = MkWrapIO (return x)

  m >>= f  = MkWrapIO (do x <- unwrap m
                          unwrap (f x) )

Simon Peyton Jones's avatar
Simon Peyton Jones committed
23
  fail str = error str