user467526
user467526

Reputation: 527

Using liftIO and monad transformers, why is the type of a bound variable IO List instead of List?

I'm using EitherT in conjunction with IO for error handling. I have a function in the IO monad that gets data from a database so it has a type of IO [Value]. I use liftIO to lift this function into my EitherT IO monad and bind the result of this function to a variable. The problem is that GHC is telling me that the variable has the type IO [Value] instead of just [Value]. My code looks like this

    getItem :: (IConnection a) => a -> ItemId -> EitherT String IO Item
    getItem conn id = do
                    result <- liftIO $ do
                                        ... database stuf

It seems like i'm misunderstanding how liftIO and binding variables works. I thought that liftIO would take IO [Value] and return EitherT String IO [Value] and when bound to a variable, it would have the type [Value]. But it seems like I'm mistaken.

Upvotes: 0

Views: 506

Answers (1)

user467526
user467526

Reputation: 527

I figured out my issue. I was calling return on a value that was already an IO value, leading to IO (IO [Value]).

Upvotes: 3

Related Questions