Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Monad problem (Ren? Kla?an)
2. Re: Monad problem (Bob Ippolito)
3. Re: Monad problem (Imants Cekusins)
4. Re: Monad problem (Marcin Mrotek)
5. Re: Monad problem (Ren? Kla?an)
----------------------------------------------------------------------
Message: 1
Date: Sat, 11 Jul 2015 14:16:36 +0200
From: Ren? Kla?an <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Monad problem
Message-ID:
<cad8jy_mykbpaaqa4_jggsbbu41vqdksez4nao9rhaqn8hbs...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150711/568e3af1/attachment-0001.html>
------------------------------
Message: 2
Date: Sat, 11 Jul 2015 10:52:34 -0700
From: Bob Ippolito <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Monad problem
Message-ID:
<CACwMPm9VyjvddnOUeTSO=4_k2k_brjhf5jl8vqwmm_wy_um...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
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-Resource.html#v:runResourceT
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 <[email protected]> wrote:
> 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
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150711/39925eb3/attachment-0001.html>
------------------------------
Message: 3
Date: Sat, 11 Jul 2015 20:41:25 +0200
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Monad problem
Message-ID:
<CAP1qinamDrVhebv4+J0DJGcCsF=wvvapqhybyk7219mm7hy...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
> Many libraries use a monad transformer stack on top of IO rather than a
> direct IO interface.
Does this mean that they do not perform IO, or do IO but "break out
of" / hide their IO using unsafe or something?
if we tried to call runInstagramT from a regular (non-IO) "do", would
it have worked without runResourceT?
------------------------------
Message: 4
Date: Sat, 11 Jul 2015 21:09:54 +0200
From: Marcin Mrotek <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Monad problem
Message-ID:
<CAJcfPzmOvAd+RrYbsy9H=6=txa4tfzwfu-yyk0nxnakugrk...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Hello,
> Does this mean that they do not perform IO, or do IO but "break out
of" / hide their IO using unsafe or something?
No, monad transformers sort of compose "backwards", that is, if you
have something like FooT (BarT (IO a)) then after running everything,
you'll get something in the lines of IO (Bar (Foo a)). That's why IO,
if it is there at all, must be at the bottom of the stack.
Now, I don't know the library you're using, from the docs it would
appear that you indeed can runInstagramT without any IO in there, but
some of the actions defined force this or that constraint, and in
particular this "getUserAccessTokenURL2" forces (MonadControlBase IO
m), which is more or less a fancy way of saying that there must be IO
at the bottom.
Best regards,
Marcin Mrotek
------------------------------
Message: 5
Date: Sat, 11 Jul 2015 22:42:27 +0200
From: Ren? Kla?an <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Monad problem
Message-ID:
<cad8jy_o7w4mdm0g_ph43smrzvqy9d-9uuzne+usnsn+ybzh...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Bob Ippolito, thank you for great explanation! Your suggestion is working.
Marcin Mrotek, thank you for additional info.
On Sat, Jul 11, 2015 at 9:09 PM, Marcin Mrotek <[email protected]>
wrote:
> Hello,
>
> > Does this mean that they do not perform IO, or do IO but "break out
> of" / hide their IO using unsafe or something?
>
> No, monad transformers sort of compose "backwards", that is, if you
> have something like FooT (BarT (IO a)) then after running everything,
> you'll get something in the lines of IO (Bar (Foo a)). That's why IO,
> if it is there at all, must be at the bottom of the stack.
>
> Now, I don't know the library you're using, from the docs it would
> appear that you indeed can runInstagramT without any IO in there, but
> some of the actions defined force this or that constraint, and in
> particular this "getUserAccessTokenURL2" forces (MonadControlBase IO
> m), which is more or less a fancy way of saying that there must be IO
> at the bottom.
>
> Best regards,
> Marcin Mrotek
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150711/a0c250bd/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 85, Issue 7
****************************************