Async/await - .NET compatible implementation

231 views
Skip to first unread message

Marek Gibek

unread,
Jun 18, 2012, 1:36:40 PM6/18/12
to nemer...@googlegroups.com
I've just watched "Philip Laureano - I Can't Believe It's Not Roslyn" video (http://vimeo.com/43612919) and I am thrilled. Really!! Meta programming in .NET is what I needed since I started using WPF. So after watching the move I was so excited.

But I didn't want to learn new language as I'm using C# at work. And I started investigating Roslyn. But I was using VS 2012 RC and liked new await/async language features. Roslyn doesn't implement them yet. Nemerle too (not that await/async like .NET's 4.5 feature - Nemerle's concurrency.n uses Threads which is very different - and in my opinion less flexible/efficient - correct me if I'm wrong). But Nemerle is ready too use. But not in VS 2012. So I thought maybe use Roslyn and I won't have to learn new language. Or maybe I will use any existing C# parser and do C# compile-time transformations myself. But after trying to use syntax unknown for VS and I saw that it would work well without integration with editor and intellisense - too much trouble. I was torn - none of the solutions was ideal. I wanted to give a try to Roslyn, but then it refused installing :) Grrrr....

So here I am. Maybe that's better. Maybe I will appreciate another Nemerle's features. I will give it a try at least. Do I have any choice? :) It's the first not mainstream language that attracted my attention. As you see it can give me the fastest access to metaprogramming in .NET. I hope that the integration with VS 2012 is planned in a near future....

As I said one reason of my indecision was async/await functionality. I wanted it all :) And hey! Roslyn couldn't give me it now. But Nemerle - why not? It's true it is targetting only .NET 4.0 now. But there is Microsoft's AsyncTargettingPack for .NET 4.0. It requires VS2012 compiler, true. But Nemerle is an extensible compiler. And compiled async code uses standard .NET 4.0 features. There is state-machine struct underneath. Rest is included in AsyncTargettingPack dll.

And now my question is:

         Is anyone working on this async/await featue compatible with .NET 4.5 async/await for Nemerle?

Because if not, I would like to try myself. It sounds so interesting that I cannot resist. To make it clear - I'm not saying that I will accomplish anything!! I even don't know the basics of the language, yet. First I need to learn it. And I can do it only in my free time (which is very short). And it is not a trivial macro to write. Especially when it takes loops and try/catch statements into account. Maybe I will give up in a middle. Who knows. But I know that if its done it will not need any change when migrating to .NET 4.5. And it can be compatible with other .NET's async code.

         Is there any interest for that kind of functionality?

         Can I count on your help in difficult situations? :)

         I think the macro possible. But I don't know the language yet. Do you know any obstacles? For example - will I have any troubles with generating private structs nested in classes, attributes for methods, goto's and labels for state machine?

         I don't know Nemerle design goals. Is it the preffered way to implement it as macro? How the future versions of Nemerle and Nemerle's C# compiler (that is a big question for me) will handle this async/await functionality? Will the code be shared or different for both compilers? Will it be a macro or what?

Ok. But before anything else I'm going to start learning the basics :))

Best Regards,
Marek Gibek

gerrcrazzy

unread,
Jun 19, 2012, 3:24:41 AM6/19/12
to nemer...@googlegroups.com

You need more recent macro library named "Computation Expressions" (github, wiki, samples). But even in this library implementation of "async" feature is different with C# (author say's it's closer to F# async).

About a year ago in russian forum one man asked: "Do you plan implement async/await from future versions of C#?" and answer was: "No, we are already have Computation Expressions".

If you still want to start learn Nemerle here is english version of Vladislav Chistyakov articles for beginners (translation currently in progress).

Marek Gibek

unread,
Jun 19, 2012, 6:48:31 AM6/19/12
to nemer...@googlegroups.com
Thank you!! It is a very helpful answer.

I didn't know about new "Computation Expressions". It's much better than "concurrency.n" macro. First of all it is now not only about threads but also introduces ExecutionContext. It looks very similar to C#'s approach (I don't know F# but I did a quick test and F#'s async is not compatible with C#'s await out of a box too). So similar that this will be a very good start point for me.

I don't agree with a statement from forum that if we already have Computation Expressions we don't want to be compatible with C#. I need that compatibility :) I cannot cheat myself that I will use only Nemerle's assemblies even in my own solutions. Many 3rd party libraries will be created (C#'s async/await isn't in production yet). And I want to integrate with them easily. And with my own code. And vice versa. It's unavoidable in the near future, I think.

So here I am :). And I see now that the integration may be easier than I initially thought.  It's because "Computation Expressions" looks powerful enough. Maybe I don't need to generate exactly the same state machine at IL level as C#'s compiler does *). Maybe all AST transformations are already written :) Maybe the only thing I need to do is to introduce IAwaitable support. It would be great!

And I am very grateful for the link to translation of Vladislav articles. Yes, I still want to learn Nemerle! I would missed them otherwise (as they are in sandbox yet) and they look very promising.

Thanks again,
Marek Gibek


*) Maybe it would be a little bit faster. Microsoft has rewritten this state machine code at least for three times. But it's not my priority.

VladD2

unread,
Jun 20, 2012, 1:34:52 AM6/20/12
to nemer...@googlegroups.com

http://nemerle.org/wiki/index.php?title=ComputationExpression_macro

Vlad Chistyakov
www.rsdn.ru

19.06.2012 14:48 пользователь "Marek Gibek" <gib...@gmail.com> написал:у

> --
> nemerle-en Google Group, try http://groups.google.com/group/nemerle-en
> for more options.

Marek Gibek

unread,
Jun 20, 2012, 11:32:16 AM6/20/12
to Nemerle Forum
OMG! This is so fascinating! I cannot stop reading before I will know
everything about monads, closures etc. I always thought that
functional programming is for mathematicians for solving abstract
problems only and have no practical value for me. You have no idea how
happy I am that Roslyn doesn't support what I wanted yet and I decided
to give Nemerle a try.

Computation Expressions gives me all I need. Only little changes will
be needed. I think I will be able to achieve my goals in the very
first week of Nemerle's discovery. And that will take me so long,
because I want to fully understand what happens under the hood :)
That's the power of this language! So complicated task and monads will
do it :) Of course I will share my results with community. The truth
is that authors of Computation Expressions did all the work for me.

As a .NET developer I don't understand why I never heard of this
language. I need to propagate it more here in Cracow. I think that the
reason why it is like this is because most people treat it as a
curiosity.

Best Regards,
Marek Gibek


On Jun 20, 7:34 am, VladD2 <v...@rsdn.ru> wrote:
> http://nemerle.org/wiki/index.php?title=ComputationExpression_macro
>
> Vlad Chistyakovwww.rsdn.ru
>

Marek Gibek

unread,
Jun 25, 2012, 3:23:16 PM6/25/12
to nemer...@googlegroups.com
First version of .NET's Task-based Asynchronous Pattern for Nemerle 1.1 is ready and can be downloaded from here:

Marek
Reply all
Reply to author
Forward
0 new messages