Giter VIP home page Giter VIP logo

Comments (4)

rspeele avatar rspeele commented on June 12, 2024 1

I looked at the approach in your pull request and in the Query.fsi code linked by Don Syme, and at first I thought it only worked to discriminate between Generic<SpecificType> and Generic<'a>, so it wouldn't help with the Task situation, where we have ParentType and ChildType<'a>.

But I was also interested in playing around with using inline constraints more to support arbitrary awaitables, like the ValueTask type. I found that I could use a fancier version of the old bindGenericAwaitable to support Bind on any task-like using very similar rules to the C# compiler. With Task<'a> handled by the builder itself, and this new very generic inline await in an extension member, it seems to work. I tested with the existing test suite, a couple new compilation tests, and with my projects Rezoom and Rezoom.SQL that use this builder.

I also had to do something kind of weird where the inline bind is inside a static class with a generic parameter, otherwise the inference gave up on figuring out the return type in some cases (where you are using the inline Bind in the context of a non-inline generic function).

This is really abusing the compiler and is probably dependent on unspecified implementation details, but it works too well to avoid. Now, not only is unitTask obsolete, but we can let! bind arbitrary task-likes just like we can await them in C#!

Thanks again for posting about this problem on the FSharp github and finding out about the extension member trick. I had never encountered that technique before.

from taskbuilder.fs.

rspeele avatar rspeele commented on June 12, 2024

Hi,

Sadly, yes. Here is the ugly case.

type X() =
    member this.Num = 0

let xTask : Task<X> = task { return X() }

let badTask =
    task {
        let! x = xTask
        return x.Num + 1
        //      ^ FS0072: Lookup on object of indeterminate type based on
        //        information prior to this program point.
    }

I think that your example works because of the special inference on record properties (i.e. same reason you could write let f x = x.A + x.B).

I would be really glad to get rid of unitTask if I could.

from taskbuilder.fs.

0x53A avatar 0x53A commented on June 12, 2024

Thanks! I created dotnet/fsharp#3281, let's see what happens.

from taskbuilder.fs.

0x53A avatar 0x53A commented on June 12, 2024

Nice!

from taskbuilder.fs.

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.