GithubHelp home page GithubHelp logo

Comments (9)

TheAngryByrd avatar TheAngryByrd commented on July 27, 2024

Sounds like a good addition!

from fstoolkit.errorhandling.

TheAngryByrd avatar TheAngryByrd commented on July 27, 2024

We have a function for that ofTaskAction .

from fstoolkit.errorhandling.

ysangkok avatar ysangkok commented on July 27, 2024

I tried that, this is the error I get:

Lightning.fs(237,94): 
error FS0001: The type 'unit' is not compatible with the type 'Task' [Backend.fsproj]
  
Lightning.fs(237,13): 
error FS0041: A unique overload for method 'Bind' could not be determined based on type information prior to this program point. A type annotation may be needed. 
Candidates: 
member AsyncResultBuilder.Bind : async':Async<'T> * binder:('T -> Async<Result<'U,'TError>>) -> Async<Result<'U,'TError>>, 
member AsyncResultBuilder.Bind : asyncResult:Async<Result<'T,'TError>> * binder:('T -> Async<Result<'U,'TError>>) -> Async<Result<'U,'TError>>, 
member AsyncResultBuilder.Bind : result:Choice<'T,'TError> * binder:('T -> Async<Result<'U,'TError>>) -> Async<Result<'U,'TError>>, 
member AsyncResultBuilder.Bind : result:Result<'T,'TError> * binder:('T -> Async<Result<'U,'TError>>) -> Async<Result<'U,'TError>>, 
member AsyncResultBuilder.Bind : task:Task * binder:(unit -> Async<Result<'T,'TError>>) -> Async<Result<'T,'TError>>, member AsyncResultBuilder.Bind : task:Task<'T> * binder:('T -> Async<Result<'U,'TError>>) -> Async<Result<'U,'TError>>, 
member AsyncResultBuilder.Bind : taskResult:Task<Result<'T,'TError>> * binder:('T -> Async<Result<'U,'TError>>) -> Async<Result<'U,'TError>> [Backend.fsproj]

from fstoolkit.errorhandling.

ysangkok avatar ysangkok commented on July 27, 2024

let me prepare a complete example...

from fstoolkit.errorhandling.

ysangkok avatar ysangkok commented on July 27, 2024

Actually, I get an error even with this:

namespace Lightning

open FsToolkit.ErrorHandling
module Lightning =

    let Test () =
        asyncResult {
            do! async { return (Ok "test") }
            return ()
        }

the error is

Lightning.fs(8,13): error FS0041: No overloads match for method 'Bind'. The available overloads are shown below. [Backend.fsproj]
  Possible overload: 'member AsyncResultBuilder.Bind : asyncResult:Async<Result<'T,'TError>> * binder:('T -> Async<Result<'U,'TError>>) -> Async<Result<'U,'TError>>'. Type constraint mismatch. The type     'unit -> Async<Result<unit,'c>>'    is not compatible with type    'string -> Async<Result<'a,'b>>'    .
  Possible overload: 'member AsyncResultBuilder.Bind : taskResult:System.Threading.Tasks.Task<Result<'T,'TError>> * binder:('T -> Async<Result<'U,'TError>>) -> Async<Result<'U,'TError>>'. Type constraint mismatch. The type     'Async<Result<string,'c>>'    is not compatible with type    'System.Threading.Tasks.Task<Result<'a,'b>>'    .
  Possible overload: 'member AsyncResultBuilder.Bind : result:Result<'T,'TError> * binder:('T -> Async<Result<'U,'TError>>) -> Async<Result<'U,'TError>>'. Type constraint mismatch. The type     'Async<Result<string,'c>>'    is not compatible with type    'Result<'a,'b>'    .
  Possible overload: 'member AsyncResultBuilder.Bind : result:Choice<'T,'TError> * binder:('T -> Async<Result<'U,'TError>>) -> Async<Result<'U,'TError>>'. Type constraint mismatch. The type     'Async<Result<string,'c>>'    is not compatible with type    'Choice<'a,'b>'    .
  Possible overload: 'member AsyncResultBuilder.Bind : task:System.Threading.Tasks.Task * binder:(unit -> Async<Result<'T,'TError>>) -> Async<Result<'T,'TError>>'. Type constraint mismatch. The type     'Async<Result<string,'a>>'    is not compatible with type    'System.Threading.Tasks.Task'    .
  Possible overload: 'member AsyncResultBuilder.Bind : task:System.Threading.Tasks.Task<'T> * binder:('T -> Async<Result<'U,'TError>>) -> Async<Result<'U,'TError>>'. Type constraint mismatch. The type     'Async<Result<string,'b>>'    is not compatible with type    'System.Threading.Tasks.Task<'a>'    .
  Possible overload: 'member AsyncResultBuilder.Bind : async':Async<'T> * binder:('T -> Async<Result<'U,'TError>>) -> Async<Result<'U,'TError>>'. Type constraint mismatch. The type     'unit -> Async<Result<unit,'d>>'    is not compatible with type    'Result<string,'a> -> Async<Result<'b,'c>>'

Is this not compatible with F# 4.5?

from fstoolkit.errorhandling.

TheAngryByrd avatar TheAngryByrd commented on July 27, 2024

Hmm we have a test that does bind against a unit task.

testCaseAsync "Bind Task" <| async {
let innerData = "Foo"
let! actual = asyncResult {
do! Task.FromResult innerData :> Task
}
Expect.equal actual (Result.Ok ()) "Should be ok"

Is this not compatible with F# 4.5?

Version 1.2.6 requires FSharp 4.6.2.

from fstoolkit.errorhandling.

TheAngryByrd avatar TheAngryByrd commented on July 27, 2024

It doesn't look like there's a good reason to not drop the minimum required FSharp.Core version, I'll open a PR for that.

from fstoolkit.errorhandling.

TheAngryByrd avatar TheAngryByrd commented on July 27, 2024
namespace Lightning

open FsToolkit.ErrorHandling
module Lightning =

    let Test () =
        asyncResult {
            do! async { return (Ok "test") }
            return ()
        }

do! is invalid here since you're trying to bind against something that has data. In your case the value "Test". You have two options.

Ignore the result:

 let! _ = async { return Ok "test" }

or have the value be a unit:

do! async { return Ok () }

from fstoolkit.errorhandling.

ysangkok avatar ysangkok commented on July 27, 2024

Aaaah, thank you so much! It makes sense, I get it. Indeed I would appreciate if the min version was F# 4.5, since that is what the Mono packages for Ubuntu ships.

from fstoolkit.errorhandling.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.