Trouble with haskey/mtl

Hello There! This is my first question post, I hope I’m asking at the right place :slight_smile:

I’m trying to plug a mysql replication client with haskey-mtl
but I’m struggling with the mtl stack:

I created an issue there: https://github.com/haskell-haskey/haskey-mtl/issues/5 that describes the problem:

src/Graphs.hs:113:25: error:
    • Couldn't match type ‘App’ with ‘IO’
      Expected type: IO ()
        Actual type: App ()

The code is available here: https://github.com/docteurklein/grap-hs/blob/main/src/Graphs.hs#L113

Any idea? I tried using MonadBaseControl without success.

Thanks for reading!

1 Like

I haven’t tried running it, but:

When you wrote

    liftIO $ BinLog.getLastBinLogTracker conn >>= \ case

The whole computation to the right of liftIO needs to be IO, meaning

    BinLog.getLastBinLogTracker conn >>= \ case
        Just tracker -> do
            es <- BinLog.decodeRowBinLogEvent =<< BinLog.dumpBinLog conn 1024 tracker False
            forever $ do
                Streams.read es >>= \ case
                    Just (BinLog.RowWriteEvent _timestamp  _tracker table events)  ->
                        insertEvents []  -- events
                    Nothing -> return ()
        Nothing -> error "can't get latest binlog position"

This is supposed to be in IO, but insertEvents is in App, and you are searching for a way to lower it into IO. Instead of that, try to lift the other IO parts to App using liftIO! Like this (I think, if it doesn’t quite work try to massage it a bit, I haven’t run the code :slight_smile: ):

    liftIO (BinLog.getLastBinLogTracker conn) >>= \ case
        Just tracker -> do
            es <- liftIO $ BinLog.decodeRowBinLogEvent =<< BinLog.dumpBinLog conn 1024 tracker False
            forever $ do
                liftIO (Streams.read es) >>= \ case
                    Just (BinLog.RowWriteEvent _timestamp  _tracker table events)  ->
                        insertEvents []  -- events
                    Nothing -> return ()
        Nothing -> error "can't get latest binlog position"

thanks for the clear explantion! that was it.

1 Like