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. Re: Monad problem (Marcin Mrotek)
2. Re: Monad problem (Imants Cekusins)
3. Re: Monad problem (Marcin Mrotek)
----------------------------------------------------------------------
Message: 1
Date: Sun, 12 Jul 2015 09:39:05 +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:
<cajcfpzmfpqquycaxfc-isgsd0v_y7phlj_zlqec2dxe535g...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Imants Cekusins,
Well using monad transformers like that is a fairly common design
pattern in Haskell, so I think you should get used to it ;) But you
don't really need to understand monad transformers in depth just to
use the ig library, it appears that all actions defined there have a
type like
:: (MonadBaseControl IO m, MonadResource m) => _ some arguments _
-> InstagramT m _result_
The smallest monad that satisfies both (MonadBaseControl IO m) and
(MonadResource m) is just (ResourceT IO), so the code suggested by Bob
Ippolito
token <- runResourceT . runInstagramT credentials manager $
getUserAccessTokenURL2 redirectUrl code
works, because "getUserAccessTokenURL2 redirectUrl code" has type
"InstagramT (ResourceT IO) OAuthToken". It is one of Haskell's
features that the actual concrete type of an expression is inferred
according to the context in which it appears, and thus may vary.
* The whole thing starts with the type "MonadBaseControl IO m,
MonadResource m => InstagramT m OAuthToken"
* runInstagramT strips the InstagramT layer, leaving "MonadBaseControl
IO m, MonadResource m =>m OAuthToken"
* runResourceT has type "MonadBaseControl IO m => ResourceT m a -> m
a", so Haskell infers that the "m OAuthToken" above is actually
"MonadBaseControl IO m => ResourceT m OAuthToken". The satisfaction of
the MonadResource constraint is provided by the ResouceT layer itself,
which is stripped by runResourceT then.
* at the end, Haskell is left with "MonadBaseControl IO m => m
OAuthToken", which it tries to unify with "IO something", because
you're using it in the do block of main, that must have the type IO ()
in the end. As "IO OAuthToken" does satisfy this constraint,
everything is fine.
The library uses type classes instead of this concrete type, because
some users might want to supply a more complicated monad transformer
stack than that, but of course you don't actually have to do this.
Best regards,
Marcin Mrotek
------------------------------
Message: 2
Date: Sun, 12 Jul 2015 09:59:38 +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:
<cap1qinbnu2qsdgppwv8ce74v0yymsfvtmyz3c_qnefjpanw...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Cheers Marcin,
One more question:
MonadBaseControl IO m, MonadResource m => getUserAccessTokenURL2
however
Monad m => getUserAccessTokenURL1
if we used getUserAccessTokenURL1, would we be able to access result
"a" (Text in this case) with:
token <- runInstagramT ...
?
------------------------------
Message: 3
Date: Sun, 12 Jul 2015 10:21:50 +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:
<cajcfpzkfpqzqcbt9d1ey-xu2m3rmnu11hmrjn59zusuevm2...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
Yes, apparently the getUserAccessTokenURL1 action doesn't do any IO or
use the ResourceT transformer, so you can bind it directly to IO
actions. Actually, since it works with literally any monad, you could
instantiate it Identity and run it as a pure computation:
let token = runIdentity . runInstagram ...
Best regards,
Marcin Mrotek
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 85, Issue 8
****************************************