
Great question! Many libraries use a monad transformer stack on top of IO
rather than a direct IO interface. This can be convenient if you are also
using such a stack, but it certainly complicates things a bit if you're
just in IO directly.
If you follow the error messages it says that it's expecting your Monad to
have an instance of MonadResource. IO does not (or else it would've just
worked). This means that you'll need to find a monad transformer that
provides MonadResource. By looking at the name "
Control.Monad.Trans.Resource.Internal.MonadResource" I know that I should
probably start looking for something called "Control.Monad.Trans.Resource".
After a bit of searching on Hackage I found
http://hackage.haskell.org/package/resourcet
The relevant function is `runResourceT` (most monad transformers are going
to have a similarly named run function to "unwrap" a transformer):
http://hackage.haskell.org/package/resourcet-1.1.5/docs/Control-Monad-Trans-...
Something like this should compile:
{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Client
import Instagram
import Control.Monad.Trans.Resource
code = "xxx_some_code"
redirectUrl = "http://localhost:9988/instagram/oauth2/callback"
credentials = Credentials "xxx_some_api_id" "xxx_some_api_secret"
main :: IO ()
main = do
manager <- newManager defaultManagerSettings
token <- runResourceT . runInstagramT credentials manager $
getUserAccessTokenURL2 redirectUrl code
print token
On Sat, Jul 11, 2015 at 5:16 AM, René Klačan
Hi all,
I've been trying to create working example with "ig" https://hackage.haskell.org/package/ig-0.2.2 - library over instagram API and I am facing little monad problem.
Can someone advise me please how to make this small piece of code work?
{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Client import Instagram
code = "xxx_some_code" redirectUrl = "http://localhost:9988/instagram/oauth2/callback" credentials = Credentials "xxx_some_api_id" "xxx_some_api_secret"
main :: IO () main = do manager <- newManager defaultManagerSettings token <- runInstagramT credentials manager $ getUserAccessTokenURL2 redirectUrl code print token
I am getting following error:
src/Main.hs:14:9: No instance for (Control.Monad.Trans.Resource.Internal.MonadResource IO) arising from a use of ‘getUserAccessTokenURL2’ In the second argument of ‘($)’, namely ‘getUserAccessTokenURL2 redirectUrl code’ In a stmt of a 'do' block: token <- runInstagramT credentials manager $ getUserAccessTokenURL2 redirectUrl code In the expression: do { manager <- newManager defaultManagerSettings; token <- runInstagramT credentials manager $ getUserAccessTokenURL2 redirectUrl code; print token }
Thanks
Rene
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners