concurrent ml versus go

20 September 2016 9:33 PM (concurrency | go | ml | ignorance | guile)

Peoples! Lately I've been navigating the guile-ship through waters unknown. This post is something of an echolocation to figure out where the hell this ship is and where it should go.

Concretely, I have been working on getting a nice lightweight concurrency system rolling for Guile. I'll write more about that later, but you can think of it as being modelled on Go, though built as a library. (I had previously described it as "Erlang-like", but that's just not accurate.)

Earlier this year at Curry On this topic was burning in my mind and of course when I saw the language-hacker fam there I had to bend their ears. My targets: Matthew Flatt, the amazing boundary-crossing engineer, hacker, teacher, researcher, and implementor of Racket, and Matthias Felleisen, the godfather of the PLT research family. I saw them sitting together and I thought, you know what, what can they have to say to each other? These people have been talking together for 30 years right? Surely they are actually waiting for some ignorant dude to saunter up to the PL genius bar, right?

So saunter I do, saying, "if someone says to you that they want to build a server that will handle 100K or so simultaneous connections on Racket, what abstraction do you tell them to use? Racket threads?" Apparently: yes. A definitive yes, in the case of Matthias, with a pointer to Robby Findler's paper on kill-safe abstractions; and still a yes from Matthew with the caveat that for the concrete level of concurrency that I described, you'd have to run tests. More fundamentally, I was advised to look at Concurrent ML (on which Racket's concurrency facilities were based), that CML was much better put together than many modern variants like Go.

This was very interesting and new to me. As y'all probably know, I don't have a formal background in programming languages, and although I've read a lot of literature, reading things only makes you aware of the growing dimension of the not-yet-read. Concurrent ML was even beyond my not-yet-read horizon.

So I went back and read a bunch of papers. Turns out Concurrent ML is like Lisp in that it has a tribe and a tightly-clutched history and a diaspora that reimplements it in whatever language they happen to be working in at the moment. Kinda cool, and, um... a bit hard to appreciate in the current-day context when the only good references are papers from 10 or 20 years ago.

However, after reading a bunch of John Reppy papers, here is my understanding of what Concurrent ML is. I welcome corrections; surely I am getting this wrong.

1. CML is like Go, composed of channels and goroutines. (Forgive the modern referent; I assume most folks know Go at this point.)

2. Unlike Go, in CML a channel is never buffered. To make a buffered channel in CML, you spawn a thread that manages a buffer between two channels.

3. Message send and receive operations in CML are built on a lower-level primitive called "events". (send ch x) is instead euivalent to (sync (send-event ch x)). It's like an event is the derivative of a message send with respect to time, or something.

4. Events can be combined and transformed using the choose and wrap combinators.

5. Doing a sync on an event created by choose allows a user to build select in "user-space", as a library. Cool stuff. So this is what events are for.

6. There are separate event type implementations for timeouts, channel send/recv blocking operations, file descriptor blocking operations, syscalls, thread joins, and the like. These are supported by the CML implementation.

7. The early implementations of Concurrent ML were concurrent but not parallel; they did not run multiple "goroutines" on separate CPU cores at the same time. It was only in like 2009 that people started to do CML in parallel. I do not know if this late parallelism has a practical impact on the viability of CML.

ok go

What is the relationship of CML to Go? Specifically, is CML more expressive than Go? (I assume the reverse is not the case, but that would also be an interesting result!)

There are a few languages that only allow you to select over message receives (not sends), but Go's select doesn't have this limitation, so that's not a differentiator.

Some people say that it's nice to have events as the common denominator, but I don't get this argument. If the only event under consideration is message send or receive over a channel, events + choose + sync is the same in expressive power as a built-in select, as far as I can see. If there are other events, then your runtime already has to support them either way, and something like (let ((ch (make-channel))) (spawn-fiber (lambda () (put-message ch exp))) (get-message ch)) should be sufficient for any runtime-supported event in exp, like sleeps or timeouts or thread joins or whatever.

To me it seems like Go has made the right choices here. I do not see the difference, and that's why I wrote all this, is to be shown the error of my ways. Choosing channels, send, receive, and select as the primitives seems to have the same power as SML events.

Let this post be a pentagram on the floor, then, to summon the CML cognoscenti. Well-actuallies are very welcome; hit me up in the comments!

[edit: Sam Tobin-Hochstadt tells me I got it wrong and I believe him :) In the meantime while I work out how I was wrong, examples are welcome!]

56 responses

  1. kamstrup says:

    One thing where Go's select immediately falls short in your example with N connections is that you can't naturally select{} on a set of channels not known at compile time. Select in Go is a language construct and not a function; which seems to be an issue I run into pretty much every time I use it[1]. Maybe it's just me.

    [1]: I'm aware that there is helper API for dynamic selects in Go, but it feels clumsy, not to mention odd, that there are two different ways to do what is conventionally not distinct (select() in C works identically in both cases).

  2. Vesa Karvonen says:

    As said in an earlier comment, CML's choose allows choice over a run-time generated set of operations, which is sometimes necessary. AFAIK, this is not supported by Go. An example would be the selectable queue example from kill safe abstractions paper.

    What CML events give you over Go style select over channel ops is a way to encapsulate protocols as events. An event can include a preparation step (e.g. send message to server), the actual synchronizing operation (e.g. get result message from server), and an after step (e.g. map over result).

    Sometimes servers need to be notified of cancellation and the negative acknowledgment feature of CML allows you to encapsulate that also as part of an event.

    Assuming your select allows to make an exclusive choice over a run-time generated set of get/put operations, allows multiple operations per channel, and allows you to determine which operation was selected, then you can implement CML style events on top with relative ease. Clojure's core.async doesn't quite pass those requirements, but here is an almost full POC of CML style events on top of core.async:

  3. srean says:

    Concurrency related abstractions in Felix (quite a bit older than Go) are quite relevant to this dicussion

  4. Richard says:

    You might be interested in reading about Occam (and the Transputer hardware that ran it.)

    That was the original concurrent (and hardware parallel) system, with an incredibly simple, innovative, and elegant design. (Arguably we went backwards by decades since then.)

    Xmos ( is an modern derivative of the Transputer from perhaps the key person behind it.

  5. Aram Hăvărneanu says:

    > CML's choose allows choice over a run-time generated set of operations, which is sometimes necessary. AFAIK, this is not supported by Go.

    It is supported by Go:

  6. solrize says:

    You should look at the paper on the current GHC I/O system if you haven't yet:

  7. Benjamin says:

    Impressive web site, Distinguished feedback that I can tackle. Im moving forward and may apply to my current job as a pet sitter, which is very enjoyable, but I need to additional expand.

  8. how to use root explorer says:

    Amazing website, i don't want to move forward when i read this awesome feedback.

  9. FastPokeMap says:

    we have easily to found the Pokemon nearby your location. Pokemon Tracker Apk is an app which provides tracking service for discovering the location of any Pokemon that’s been found by other players in your Area.
    Download FastPokeMap apk

  10. SB Game Hacker APK says:

    If you are the biggest game lover and played Clash of Clans, Temple Run and Subway Surfers more popular game with the score then you must know about the “Game Hacker APK’. If you haven’t heard about the SB Game Hacker APK yet then here you can get everything about the popular Game Hacker App.Game Hacker APK

  11. Sonny says:

    Maintain the nice perform, My partner and i examine handful of content with this internet site and also I do believe your net website will be genuine intriguing and contains received sectors regarding great details.

  12. jarmin says:

    While aiming to introduce Setbeat, Setbeat APK you could see the message Untrusted Business Developer.

  13. jeck says:
  14. yug says:

    how do they feature individuals, Download we discovered that just attractive and also eye-catching profiles are getting included on application.

  15. Charles says:

    The monster with eyeglasses without eyeglasses for iPhone. downlodable driver From Hello-Hello: Tell your beloved one how much you love him/her in 6 different languages.

  16. Edward says:

    - Redesigned Interface With iOS 8 Style;- iPad, iPhone 4/5/6/6 Plus support. this site. With Chase GiftShelf, giving a gift is just as fun as getting one.

  17. Maleah says:

    Sometimes passwords can be a bit difficult to remember. Especially when it belongs to your icloud account. We can show you how to unlock icloud very fast and easy.

  18. Kevin says:

    how do they feature individuals, Download we discovered that just attractivesite

  19. Tommy Newman says:

    Very informative article. Look to read more of your posts.

  20. Reuben says:

    Speaker uses Penxy as a remote control to advance his or her slides via Wi-Fi. checkout this. Are you confused by the 400+ Hanyu Pinyin's pronunciations.

  21. Ellis says:

    Important News:We are extremely sorry for the major inconvenience and lack of updates. The html to pdf converter can be used for free in any .

  22. Arthur George says:

    The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.

  23. klik disini says:

    The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.

  24. Patel says:

    Amazing website, i don't want to move forward when i read this awesome feedback.Freedom APK

  25. Aerocity Call Girls says:

    Simply wish to say your article is as outstanding. The clearness on your submit is just excellent and i can suppose you are an expert on this subject.

  26. hotmail login says:

    It's great idea. You're true.

  27. Devayani Kaur says:

    Really structured and useful information. And everything is clear, thanks. I looked through some posts and must say, they are very interesting.

  28. Nikita says:

    I genuinely looking for the best and interesting elements thati only found on this web page. have you seen it yet?

  29. Arian Putri says:

    Impressive web site, Distinguished feedback that I can tackle

  30. fredluis says:

    Your blog is very informative and great. Its very great read for me because your writing skills is so good and you will write this post in very good manner. Thanks! carpet cleaning

  31. Islamabad Car says:

    very well written, I am a driver in a rent a car company in Pakistan, Love to be its part.

  32. mumbai escorts says:

    I like visiting you site since I always come across interesting articles like this one.Great Job, I greatly appreciate that.Do Keep sharing!

  33. escsorts in mumbai says:

    Truly, this article is really one of the very best in the history of articles. I am a antique ’Article’ collector and I sometimes read some new articles if I find them interesting.

  34. mumbai escorts says:

    hy nice article i like so much and thanks for sharing that wonderful information.

  35. mmbai escorts says:

    amazing post

  36. madhukochi says:

    kochi best choice for you

  37. Essay Help Online says:

    I wanted to thank you for this websites! Thanks for sharing.

  38. Genuine Leather Jacket Womens says:

    I have read so many posts concerning the blogger lovers but this article is genuinely a good paragraph,

  39. samsung firmware says:


  40. crack tool says:

    I have read so many posts concerning the blogger lovers but this article is genuinely a good paragraph,

  41. Udaipur Call girls says:

    I have gatherings of exceptional thoughts and Read I envision your website is extremely charming and weblog articles with this Particular sort of webpage.

  42. Goa Cll girls says:

    Your Website is excellent and I'll probably keep supporting it to my companions. Much obliged to share, some really astounding posts on this specific kind of online site.

  43. Jiya Verma says:

    I Believe That's an edifying spot which Is instructed and profitable. I wish to thank you on paper this area for the endeavors you have made.

  44. Nainital Call girls says:

    You can have produced the spot which has Been brilliant with a mess of indications which has been useful. You happen to do the calling that is astonishing. Keep upwards for this intention that is surprising.

  45. Ritika Rajput says:

    I'd like to thanks with this Informative article, I extremely worth examining this educational article. I comprehend this article being formed by you alongside the web website that is rest of this is staggeringly extraordinary.

  46. Jodhpur Call girls says:

    I read I envision the Internet website is Weblog articles with this specific kind of web webpage and extremely charming and contains got areas of tips that is superb.

  47. Alisha Oberoi says:

    Hello, I Already After this link. Very Nice advice provided by here. My suggestion is Everybody is trying to trace this link you may more information.

  48. Bhawna Garg says:

    It's almost impossible to find experienced Individuals for this particular subject, however, you sound like you know what you are talking about!

  49. Riya Jain says:

    It was a great informative post. Proceed many Useful and enlightening links. Loved your writings also. Concept of this subject was well discussed.

  50. Eliza Rova says:

    I've read several excellent stuff . Certainly worth bookmarking for revisiting. I wonder how much attempt you set to make one of these fantastic

  51. Komal Mehra says:

    Great web site! It looks quite professional! Keep the helpful job, superb review, could not agree with you more. Nice! Thanks so much! Thanks for sharing.

  52. Jia Tomar says:

    Your dairy posts place unit a lot of Interesting and informative. Your writing is too good. I believe there are lots of people like and visit it regularly, including me.

  53. Kirti Modi says:

    Really like the way this website has been done. Truly awesome. Nice work done. Simply want to state your post is as astonishing.

  54. Renzy Mehtha says:

    I think this is an informative post and it Is very helpful and knowledgeable. Thus, I would love to thank you for the efforts you have made in writing this report.

  55. Vaishali Verma says:

    Thank you to this amazing read that is really Useful for me. Continue the fantastic work. Another fantastic post from you thanks so much. Fantastic hints I am going to have try and see the impact...

  56. Patna Call Girls says:

    I share your blog with on my own social websites Page constantly. Thank you for the superb read and please post more. .

Leave a Reply