Comments (2)
First question first. The current signature of >>=?
is
val (>>=?): Alt<'x> -> ('x -> Job<'y>) -> Alt<'y>
And Alt<'x>
is a subtype of Job<'x>
. So, you can use upcast
:
let rec accum sum =
Alt.choose [ Ch.Alt.take addCh >>=? fun x -> upcast accum (sum + x)
Ch.Alt.take subCh >>=? fun x -> upcast accum (sum - x)
Ch.Alt.give readCh sum >>=? fun _ -> upcast accum sum ]
Ideally F# would upcast implicitly. It would be possible to change the signature of >>=?
to
val (>>=?): Alt<'x> -> ('x -> #Job<'y>) -> Alt<'y>
In fact, many combinators could be changed similarly. I think the reasons as to why this wasn't done initially are historical: I didn't initially use subtyping/inheritance. Using the above kind of bounded quantification at covariant positions would likely reduce the overall need for upcasts, but it does not eliminate the need completely (e.g. match where different cases return different subtypes).
from hopac.
Second question. In Hopac, the job monad serves two purposes:
- it represents a thread of execution that can be suspended without blocking native threads (like
async
), and - inside the job monad there is efficient access to the scheduling infrastructure, allowing operations such as resuming another job (e.g. when a message is passed to a waiting job) to be performed efficiently.
Of the above, the first one is essential, while the second one is nice for performance. In Concurrent ML, the first feature is essentially a part of the language implementation, so there is no need for a monadic encoding of suspendable threads. In F# we don't have built-in lightweight continuations or threads, so Hopac uses the job monad.
Monadic encodings like the ones used by async
and job
are not the only ways to encode suspendable threads of execution, but they have some nice properties.
from hopac.
Related Issues (20)
- Add Azure DevOps build HOT 2
- Problems with network stream HOT 9
- Handling exceptions HOT 9
- Stack Overflow in Alt.choose HOT 3
- Fibonacci benchmark fails with Stack Overflow on NET Core, but not on Framework HOT 4
- Production Ready? HOT 5
- IAsyncEnumerable<T> interop HOT 1
- How to convert to task? HOT 6
- ValueTask<T> interop HOT 1
- How to get the build working on Windows? HOT 2
- Stack overflow with recursive job HOT 5
- Is this project dead? HOT 1
- Why do these two code snippets result in different behavior HOT 1
- FSharp.Core 5.0 support HOT 15
- Why does the left side not uncommit after the right side has been chosen when using Alt.prepare? HOT 8
- How can uncaught exception errors be redirected?
- BadImageFormatException HOT 6
- How to conCollect but stop on first exception? HOT 8
- System.Diagnostics.Activity doesn't flow properly with Hopac, resulting in incorrect telemetry correlation
- Example of paranoid function?
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 hopac.