<div dir="ltr">Hi! Sorry for the late reply<br>The "direct" issue is that you're trying to use SqlPersistT as an effect (when using it as an argument to Member in runDB) - Member expects things that are "effects" (produced by polysemy).<br><br>If you're not going to be using runDB as an "intermediate" interpreter, but rather running it as a "final" interpreter (to actually run your program) you could instead use something like this:<br><br>runDB :: forall b. Members [Embed IO, Input (Pool SqlBackend)] r => SqlPersistT IO b -> Sem r b<br>runDB query = embed . runSqlPool query =<< input<br><br>to run your db queries in IO and embed the IO in the resulting effect stack (in this case by also having an input effect from which you can receive your connection pool)</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 14, 2020 at 11:08 PM Debasish Ghosh <<a href="mailto:ghosh.debasish@gmail.com" target="_blank">ghosh.debasish@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello -<div><br></div><div>I have a typeclass like this ..<div><br></div><div><font face="monospace">class (Monad m) => DB m where<br> query :: Text -> m (Maybe Account) </font></div><div><font face="monospace"> ...</font></div><div><br></div><div>and an instance that uses persistent and sqlite ..</div><div><br></div><div><font face="monospace">instance (MonadIO m) => DB (SqlPersistT m) where<br> query ano = get (AccountKey ano)</font></div><div><font face="monospace"> ..</font><br><div><br></div><div>Now I want to move this to using an effect system - Polysemy ..</div><div><br></div><div><font face="monospace">data DB m a where<br> Query :: Text -> DB m (Maybe Account)<br> ...</font></div><div><br><font face="monospace">makeSem ''DB<br></font></div><div><br></div><div>which generates the functions .. I need some help figuring out the type of the function that interpretes the above .. An initial intuition is this ..</div><div><br></div><div><font face="monospace">runDB :: Member SqlPersistT r => Sem (DB ': r) a -> Sem r a<br>runDB = interpret $ \case<br> Query ano -> get (AccountKey ano)</font><br></div><div><br></div><div>which doesn't compile .. errors out with ..</div><div><br></div><div>Couldn't match type ‘Control.Monad.Trans.Reader.ReaderT backend0 m0 (Maybe Account)’<br> with ‘Sem r (Maybe Account)’<br> Expected type: Sem r x<br> Actual type: Control.Monad.Trans.Reader.ReaderT<br> backend0 m0 (Maybe Account)<br>• In the expression: get (AccountKey accountNo)<br></div><div><br></div><div>I think I am missing something here. The type of <font face="monospace">interpret</font> is shown as </div><div><font face="monospace">interpret :: (forall x (m :: * -> *). DB m x -> Sem r x) -> Sem (DB : r) a -> Sem r a<br></font></div><div><br></div><div>But how do I translate the <font face="monospace">SqlPersistT</font> part ? Any help will be appreciated.</div><div><br></div><div>regards.</div>-- <br><div dir="ltr"><div dir="ltr"><div>Debasish Ghosh<br><a href="http://manning.com/ghosh2" target="_blank">http://manning.com/ghosh2</a></div><div><a href="http://manning.com/ghosh" target="_blank">http://manning.com/ghosh</a><br></div><div><br>Twttr: @debasishg<br>Blog: <a href="http://debasishg.blogspot.com" target="_blank">http://debasishg.blogspot.com</a><br>Code: <a href="http://github.com/debasishg" target="_blank">http://github.com/debasishg</a></div></div></div></div></div></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>