Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# API #124

Open
mausch opened this issue Sep 9, 2016 · 2 comments
Open

C# API #124

mausch opened this issue Sep 9, 2016 · 2 comments

Comments

@mausch
Copy link

mausch commented Sep 9, 2016

I'm thinking of creating a limited API mainly around Job<T> and Promise<T>, trying to ignore other concepts as much as possible.
Monadic/applicative sugar with LINQ.
Also implement GetAwaiter to enable async/await syntax.
The rest would be mostly sugar around calling convention (e.g. uncurry functions etc)

I've not actually used Hopac personally so I'm not sure if this limited API is even viable. Do you think that would give a usable API ?

BTW this could probably be just a contrib project on a separate repo, no need to complicate the core repo :)

@mavnn
Copy link
Contributor

mavnn commented Sep 9, 2016

It sounds possible, but personally I would try very hard to fit support for Alt and Ch in - they've ended up at the core of things nearly every time I've used Hopac.

@polytypic
Copy link
Member

Here is a bit of general discussion on the concepts. I expect most here are already familiar with what I say here.

Hopac Job<T> is very much like Async<T> and Hopac Promise<T> is kind of a like a memoized Async<T>. So, roughly, if one can think of a way to use F# Async<T> nicely from C#, then a similar approach would likely work for Job<T> and probably also for Promise<T>.

With C# tasks a call of a function that returns a Task<T> effectively immediately starts a new logical thread (initially hijacking the current thread) whose result can be obtained from the returned Task<T> object. With F# async, however, the call of a function that returns an Async<T> just returns a computation that can be further composed and then ultimately needs to be explicitly run (executed as part of the current logical thread) or started (thus spawning a new logical thread).

So, both Job<T> and Async<T> represent computations that need to be explicitly run to get a value of type T. A Task<T>, OTOH, normally represents a computation that has already been started (and might have completed already). A Promise<T> represents a computation whose result will be "memoized" and that has already been started or will start when the result is requested by attempting to run (or start) the computation.

You mentioned getting fed up with C# tasks. Can you tell more?

Personally I find that the C# task model can be trickier to program with due to the way a function call effectively immediately starts a new logical thread. If you don't want to immediately start a new logical thread, you have to carefully manage the point at which the function call is made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants