Code Monkey home page Code Monkey logo

Comments (2)

polytypic avatar polytypic commented on June 3, 2024

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.

polytypic avatar polytypic commented on June 3, 2024

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)

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.