Skip to content

Trying to derive an Async<Result<'a, 'e>> from the generic monad CE #606

Answered by gusty
brandedoutcast asked this question in Q&A
Discussion options

You must be logged in to vote

Type inference gets tricky with monad transformers and generics in F#.
Anyways, your code is missing some transformations, in the right side of the let! = ... there must be a ResultT<Async<Result....

Then in order to get a ResultT from a Result you should use ResultT.hoist.

let sendAsync c ({ Url = url; Data = data } : Request<string>) =
  use reqMsg = new HttpRequestMessage(HttpMethod.Post, url)

  match data with
  | None -> ResultT (execAsync c reqMsg)
  | Some d -> monad {
      let! content = ResultT.hoist (serializeToJson d)
      reqMsg.Content <- content |> toStringContent
      return! ResultT (execAsync c reqMsg)
    }

let rec sendStrictAsync c req = monad {
  let! res = sendAs…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
5 replies
@gusty
Comment options

Answer selected by wallymathieu
@brandedoutcast
Comment options

@gusty
Comment options

@wallymathieu
Comment options

@brandedoutcast
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants