comp.lang.ada
 help / color / mirror / Atom feed
* Musings on RxAda
@ 2015-10-14 14:30 Alejandro R.  Mosteo
  2015-10-15 14:40 ` brbarkstrom
                   ` (3 more replies)
  0 siblings, 4 replies; 14+ messages in thread
From: Alejandro R.  Mosteo @ 2015-10-14 14:30 UTC (permalink / raw)


Hello all,

having been recently working on Java/Android apps, I have been exposed to 
the ReactiveX framework [1]. I think it originated on C# though.

[1] http://reactivex.io/

Anyway, the gist of it is that you chain function calls (operators in their 
jargon) to process data asynchronously. This, in Java, with lambda functions 
and parameter inference leads to extremely compact, legible code that may 
notably simplify multithreading code.

But I'm not here to advocate RxJava. For now I see it as an interesting 
challenge from an implementor point of view. When using it I started to 
think how this could be implemented in Ada. My ideas are not very elegant. 
I'd like to know your opinion/ideas on if this is doable in Ada (which could 
lead to a potential RxAda library ;-)).

For simplicity, I'm going to concentrate on the "map" operator, as seen on 
this Java example:

Observable.just("Hello, world!")
    .map(s -> s + " -Dan")
    .map(s -> s.hashCode())
    .map(i -> Integer.toString(i))
    .subscribe(s -> System.out.println(s));

Basically, the map operation takes some input, changes it somehow and 
outputs another type. The chain begins at an Observable (some data 
generator) and ends at a subscriber (which does something with the result). 
The above example takes a string, appends a signature, hashes it, and 
outputs the hash as a string. This does not necessarily has to happen at the 
moment of declaration; in general, observables emit data asynchronously.

Moving into Ada, we need an Observable type able to take different map 
implementations. That could be (not compiled, bear with my mistakes. Allow 
for 2012 syntax):

type Observable is [limited?] tagged record;
type Datum is abstract interface; -- or maybe tagged null record;

function Map (This : in out Observable; 
              Map  : access function (X : Datum'Class) return Datum'Class)
return Observable; -- or access Observable if limited

Here the 'Class are needed to avoid multiple dispatch, I think. Then you'll 
have to declare beforehand any mappings you need (which is more verbose and, 
lacking lambdas, would somehow defeat the purpose of having the logic in the 
chain declaration, but I see no way around it, unless the new simple 
expression functions can appear in-place?). Also, the need for 'Class 
parameters will force explicit casts in the user mappings, which I find ugly 
and leaves the type checks to runtime.

I guess an implementation of "RxAda" could provide many Map profile 
overloads for basic Ada types (from String to String and so on), but still 
that's a poor's man attempt.

That's as far as I've got, which is not much, but I'm a bit rusty on Ada 
right now. I can think of even more contrived ways using tagged types plus 
generics but I'm not sure they lead anywhere. I think it boils down to Ada 
not having lambda functions nor implicit template types a-la C++.

Your thoughts welcome!

[1] http://reactivex.io/


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-11-19 13:14 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-14 14:30 Musings on RxAda Alejandro R.  Mosteo
2015-10-15 14:40 ` brbarkstrom
2015-10-21 11:45 ` Hadrien Grasland
2015-10-21 12:12 ` Hadrien Grasland
2015-10-21 13:35   ` Dmitry A. Kazakov
2015-10-21 16:18     ` Hadrien Grasland
2015-10-21 16:47       ` Dmitry A. Kazakov
2015-10-21 19:09         ` Hadrien Grasland
2015-10-21 19:35           ` Dmitry A. Kazakov
2015-10-21 21:04             ` Hadrien Grasland
2015-10-22 11:02               ` Alejandro R.  Mosteo
2015-10-22 12:33                 ` Dmitry A. Kazakov
2015-10-22 16:41                   ` Alejandro R.  Mosteo
2015-11-19 13:14 ` Jacob Sparre Andersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox