Skip to content

Instantly share code, notes, and snippets.

@adz
Created January 2, 2020 00:21
Show Gist options
  • Save adz/a27b35200fec0d4e71120e028bbdb637 to your computer and use it in GitHub Desktop.
Save adz/a27b35200fec0d4e71120e028bbdb637 to your computer and use it in GitHub Desktop.
// Simulate sync action, that returns count of records synced
let syncRecords upToTimestamp : ResultT<Async<Result<int,string>>> = ResultT <| async.Return (Ok 3)
let recordTimestampUsingFSData body : Async<FSharp.Data.HttpResponse> =
FSharp.Data.Http.AsyncRequest
( "https://myapi.example.com/sync"
, httpMethod = "POST"
, body = TextRequest (sprintf "%A" body) // actually is json
, silentHttpErrors = true )
let performSync1 () =
let utcNow = DateTime.UtcNow
monad {
let! count = syncRecords utcNow
let responseRT = recordTimestampUsingFSData utcNow |> liftAsync
// This fails to compile with
// error FS0071: Type constraint mismatch when applying the default type 'obj' for a type inference variable. No overloads match for method 'LiftAsync'.
let! response = responseRT
// but compiles OK, if the following two lines are commented
if response.StatusCode < 200 || response.StatusCode >= 300 then
printfn "Sync succeeded, but failed to update bookmark"
return count
}
@adz
Copy link
Author

adz commented Jan 2, 2020

If lines #23 and #24 are put under a do then it also compile.... struggling to understand that...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment