Overriding >>= for a Monad?

Hi all, I'm using Control.Monad.StateT as such: data TapState = TapState { planSet :: Bool, noPlan :: Bool, skipAll :: Bool, testDied :: Bool, expectedTests :: Int, executedTests :: Int, failedTests :: Int } deriving (Show) type TAP a = StateT TapState IO a but I'd like to provide my own >>= function. Is there a way to "derive" a new type from StateT in order to implement my own >>=? Is thin done using "instance"? Thanks, Patrick -- ===================== Patrick LeBoutillier Rosemère, Québec, Canada

On Thu, Feb 26, 2009 at 5:46 PM, Patrick LeBoutillier
Hi all,
I'm using Control.Monad.StateT as such:
data TapState = TapState { planSet :: Bool, noPlan :: Bool, skipAll :: Bool, testDied :: Bool, expectedTests :: Int, executedTests :: Int, failedTests :: Int } deriving (Show)
type TAP a = StateT TapState IO a
but I'd like to provide my own >>= function. Is there a way to "derive" a new type from StateT in order to implement my own >>=? Is thin done using "instance"?
Thanks,
Patrick
-- ===================== Patrick LeBoutillier Rosemère, Québec, Canada
The most direct way would probably to copy StateT's source code and tinker with the >>= definition (also change the name to MyStateT or whatever). You could also define
newtype MyStateT s a = MyStateT (StateT s IO a)
instance Monad (MyStateT s) where return = MyStateT . return (>>=) = ...
Alex
participants (2)
-
Alexander Dunlap
-
Patrick LeBoutillier