Simplify Monadic Type Signature in Haskell -


I'm still new in Haskell and having trouble finding the right type signature for the function.

I have this work, using a simple code like http: // -conuit and authenticate-oauth which is a side effect, so I There is not much care about the return value:

  manager $ \ manager with executeOAuthRequest oAuth credit request = - - & gt; Signed & lt; - signOAuth oauth credit request http signed manager   

I would like to specify the correct type of signature, but output from GHCi looks terrible to me:

  executeOAuthRequest: : (Monad-control-0.3.2.3: Control.Monad.Trans.Control.MonadBaseControl IO m, control. MONAD.Trans.Resource.Internal.MonadThrowM, ControlMonad. Trans.Resource.Internal .MonadUnsafeIO m, Control Monad.IO.Class.MonadIO m) => OAuth - & gt; Credential - & gt; Request - & gt; M (ResumableSource (Resourceable M ByteString))   

The first three arguments ( OAuth , credentials , requests < / Code>) I understand, but I do not understand the long pre-condition for m and wondered if it is necessary to specify the full return value as per the suggestion of GHCi.

Instead of just providing the correct signature, I want to understand how the process of finding and reducing the right one looks like.

The GHCI is giving you the most polymorphic signature, "any type of m There is an example from MonadTrans which is reading from MonadThrow .Resource.Entertent module, Monadio , etc. "all types of typed checkers Is taking the union of those who have been started with the type of multicultural tasks you are making in the executeOAuthRequest .

Here's a simple example:

  prelude & gt; F f n = n + 1 prelude & gt; : TF - GHC estimates the polymorphic signature which is `NO ': V: number: = one => A - & gt; A Prelude & gt; F: int - & gt; Int; f n = n + 1 prelude & gt; : Tff :: int - & gt; It may be that the only way to satisfy all those constraints in your work is either  IO , or there may be many common ways to check demo Have to read or depress  
  prelude & gt; : Info IO ... Example Monad Io - Defined in GACC. Example Factor IO - Defined in GACC. Introduction & gt; : Info Monaad ... Examples Monad [] - Defined in GHC. Example Monad Io - Defined in GACC. Example Monaad ((- -> R) - Defined in GACC.   

So if you only use your function in IO , then you can type it:

  executeOAuthRequest: : OAuth - & gt; Credential - & gt; Request - & gt; IO (RespumableSource (ResourceTM) bytestrings))   

Or you can keep polymorphic signatures, for example if you are exporting this function to the library and you think That your users should use it in a different mood (perhaps by defining their new type and making it an example of MonadIO , MonadThrow , etc.) / html>

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -