Comments (4)
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.
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.
Thanks! I created dotnet/fsharp#3281, let's see what happens.
from taskbuilder.fs.
Nice!
from taskbuilder.fs.
Related Issues (20)
- Please elaborate a bit on "Tail calls are not optimized" HOT 2
- Async overload bind HOT 8
- Issue with plain Task and do! HOT 1
- TaskBuilder update breaks my tasks HOT 30
- TaskResultBuilder ? HOT 3
- TaskBuilder 2 release HOT 5
- Could not load type 'BindI' from assembly 'TaskBuilder.fs HOT 3
- Caching bool tasks HOT 2
- add support of specifying TaskScheduler HOT 4
- The type 'Threading.Tasks.Task' is not compatible with the type 'Threading.Tasks.Task<'a>' HOT 7
- Using ValueTask instead of Task HOT 1
- Intended way to call async and ignore result HOT 2
- Possible incorporation into FSHarp.Core HOT 9
- Easy way to get result synchronously? HOT 5
- Support for netstandard2.0 HOT 11
- Code is not sufficiently generic
- Question on ContextInsensitive tasks HOT 41
- Non-generic Tasks HOT 6
- What is the purpose of this if it exists in FSharpx.Extras ? HOT 3
- Dispose is not called in task CE HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from taskbuilder.fs.