I follow the instructions for monad transformers here .
At this point in the tutorial, he asks me to try to implement a Monad instance for a data type EitherIOthat is defined as:
data EitherIO e a = EitherIO {
runEitherIO :: IO (Either e a)
}
So I tried:
instance Functor (EitherIO e) where
fmap f = EitherIO . fmap (fmap f) . runEitherIO
instance Monad (EitherIO e) where
return = EitherIO . return . Right
x >>= f = join $ fmap f x
The tutorial was a bit different:
instance Monad (EitherIO e) where
return = pure -- the same as EitherIO . return . Right
x >>= f = EitherIO $ runEitherIO x >>= either (return . Left) (runEitherIO . f)
Now all types are suitable, so I thought I was good, and congratulated myself on the final search for use join.
As it turned out, later in the lesson , I was asked to run runEitherIO getTokenthe following:
liftEither x = EitherIO (return x)
liftIO x = EitherIO (fmap Right x)
getToken = do
liftIO (T.putStrLn "Enter email address:")
input <- liftIO T.getLine
liftEither (getDomain input)
>>=, GHCi . , ^C, GHCi , , . GHCi . >>= , .
.
: