Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Not being a Haskell programmer is trendy!

95 views
Skip to first unread message

Mild Shock

unread,
Feb 2, 2024, 2:46:14 PMFeb 2
to
Just watched 2 videos from Scala and the
year 2023 and nearly chocked on my yoghurt,

especially when I saw the first presenter got a
headeache from early returns. LoL

Async/Await for the Monadic Programmer
https://www.youtube.com/watch?v=OH5cxLNTTPo

DIRECT STYLE SCALA Scalar Conference 2023
https://www.youtube.com/watch?v=0Fm0y4K4YO8

Whats the bottom line: All because they discovered they
could do async/await as well?

Mild Shock

unread,
Feb 2, 2024, 3:00:44 PMFeb 2
to
BTW: The Go programming language which has direct
style runs the primes example in 0.6 seconds.
The primes example is here:

The Go Playground
https://go.dev/play/

Just choose the Concurrent Prime Sieve example.
Twice as slow as the 0.3 seconds of Haskell but
nevertheless faster than Prolog.

For those interested was comparing to:

Prolog Hand Rolled Lazy Lists via call/n:
=============================================

iter(F,A,A,iter(F,B)) :- call(F,A,B).

take(0, _, []) :- !.
take(N, C, [X|L]) :- M is N-1, call(C, X, D), take(M, D, L).

modfilt(C, M, X, E) :- call(C, Y, D), modfilt2(D, M, Y, X, E).

modfilt2(D, M, Y, X, E) :- Y mod M =:= 0, !, modfilt(D, M, X, E).
modfilt2(D, M, X, X, modfilt(D,M)).

primes(C, X, primes(modfilt(D,X))) :- call(C, X, D).

/* on @emiruz machine */
?- time(take(5000,primes(iter(succ,2)),_)).

% 38,009,267 inferences, 2.005 CPU in 2.005
seconds (100% CPU, 18954407 Lips)

true.

Haskell David Turner's sieve (SASL Language Manual, 1983)
=============================================

sieve :: [Integer] -> [Integer]

sieve [] = []

sieve (p:xs) = p : sieve [x | x <- xs, rem x p > 0]

/* on @emiruz machine */
time ./primes
% real 0m0.312s
% user 0m0.294s
% sys 0m0.005s

https://wiki.haskell.org/Prime_numbers#Turner.27s_sieve_-_Trial_division

Disclaimer: Didn't run the Go version by myself
yet. Have first to install Go etc.. Somebody
else run it and reported 0.6 seconds.

Mild Shock schrieb:
Message has been deleted
Message has been deleted

Mild Shock

unread,
Feb 11, 2024, 5:34:11 PMFeb 11
to

I tried Erlang. But it cannot deal with the problem, because actors
in Erlang have unbounded inboxes, and there is no backpressure from
the consumer back to the producers. So the iterator producer will spin

like wild and clog the processor. I can run N=100, but N=5000 explodes:
```
-module(sieve).

-export([main/1]).

above(PID, AT) ->
PID ! AT,
AT2 = AT+1,
above(PID, AT2).

filter(PID, MOD) ->
receive
AT -> if AT rem MOD =/= 0 ->
PID ! AT;
true -> true
end
end,
filter(PID, MOD).

sift(PID) ->
receive
AT -> PID ! AT,
PID2 = spawn(fun() -> sift(PID) end),
filter(PID2, AT)
end.

take(COUNT) ->
if COUNT =/= 0 ->
receive
AT -> if COUNT =:= 1 -> io:format("~w~n", [AT]);
true -> true end
end,
COUNT2 = COUNT-1,
take(COUNT2);
true -> true
end.

main(_) ->
PID = self(),
PID2 = spawn(fun() -> sift(PID) end),
spawn(fun() -> above(PID2, 2) end),
take(100).
% explodes:
% take(5000).
```

Mild Shock

unread,
Feb 11, 2024, 5:39:31 PMFeb 11
to
An interesting experiment could be to distribute such actors
via SWI-Prolog pengines over a couple of nodes in a network. Can
it handle backpressure?

How would it compare to these suggestions here:

Golang: out-of-box backpressure handling with gRPC, proven by a Grafana dashboard
gRPC and the underlying HTTP/2 protocol handle flow control. This means the server can only send data as fast as the client can consume, preventing overwhelming the client.
https://www.linkedin.com/pulse/golang-out-of-box-backpressure-handling-grpc-proven-grafana-melo

What would be the dashboard?

Mild Shock

unread,
Feb 14, 2024, 9:45:56 AMFeb 14
to

What would be cool, if the actors could interact via websockets
with each other. Not sure. Or anything that could provide some
backpressure feedback. A websocket could provide backpressure

in two ways, either by implicitly by blocking a single channel when
sending payload, if this is possible, or more explicitly by using the
other channel, for some control flow information.

BTW: I missed this one: Already 5 years old /
just before Corona [RFC 8441]:

HTTP/2 WebSockets
HTTP/2 was standardized in 2015 without any mention
of WebSockets. For most of the time since then I assumed
that there would be no WebSockets over HTTP/2. That
changed in September last year with the publication of
RFC 8441, which will be supported in browsers in 2019
approximately 10 years after WebSockets were first introduced.
https://medium.com/@pgjones/http-2-websockets-81ae3aab36dd

Mild Shock

unread,
Feb 14, 2024, 9:53:02 AMFeb 14
to
Related to gRPC, but not yet provided by nginx:

https://trac.nginx.org/nginx/ticket/1992

Mild Shock

unread,
Feb 14, 2024, 4:29:49 PMFeb 14
to
Woa! Not the direct style:

Chapter 13: Asynchronous Tasks
https://github.com/benweidig/a-functional-approach-to-java/tree/main/part-2/13-asynchronous-tasks

From this book:

Functional Approach to Java - Ben Weidig
https://github.com/benweidig/a-functional-approach-to-java/tree/main/part-2/13-asynchronous-tasks

So is this book already maculature when it was publish?

What does your crystal ball say?

Mild Shock

unread,
Feb 14, 2024, 4:33:15 PMFeb 14
to
Corr.: Wrong 2nd link. This surfaced May 19, 2023:

My book, “A Functional Approach to Java,” is finally here!
https://medium.com/@benweidig/my-book-a-functional-approach-to-java-is-finally-here-697a512f0b5b

Mild Shock

unread,
Feb 20, 2024, 7:27:04 PMFeb 20
to
My revecent Async/Await surrogates for JDK 21
provide coroutines with suspend/resume semantics.
They are not continuations. They aim is to provide
async/await and not only setTimeout().

As a result you don't need to write libraries
with a continuation parameters. This is very unlike
nonsense such as the JavaScript express web framework.

stackfulness
In contrast to a stackless coroutine a stackful
coroutine can be suspended from within a nested
stackframe. Execution resumes at exactly the same
point in the code where it was suspended before.

stackless
With a stackless coroutine, only the top-level routine
may be suspended. Any routine called by that top-level
routine may not itself suspend. This prohibits
providing suspend/resume operations in routines within
a general-purpose library.
https://www.boost.org/doc/libs/1_57_0/libs/coroutine/doc/html/coroutine/intro.html#coroutine.intro.stackfulness


Mild Shock schrieb:

Mild Shock

unread,
Feb 20, 2024, 7:28:15 PMFeb 20
to
Its also proof of concept that no stack copying
is necessary. Well its not 100% true the Prolog
interpreter does a little bit unwind and rewind

during the '$YIELD'/1 instruction. But we do
nowhere copy some native stack, this is unlike
Martin Odersky's speculation, he might implement

someting with stack copying. Except that a virtual
threads might using a copying when they resize
their stack, I don't see any need for copying.

Also sometimes a callback can be piggy packed on
an existing coroutine if it doesn't yield itself,
I am already using this in Dogelog Player as an

optimization. The idea to use semaphores in my
implementation can be credited to this paper
from 1980 where semaphores are the main switchpoint:

Extension of Pascal and its Application to
Quasi-Parallel Programming and Simulation, Software -
Practice and Experience, 10 (1980), 773-789
J. Kriz and H. Sandmayr
https://www.academia.edu/47139332

But my experience with JDK 21 virtual threads
is still poor, I am only beginning to explore them
as a way to have a large number of coroutines.

Mild Shock schrieb:

Mild Shock

unread,
Feb 20, 2024, 7:30:03 PMFeb 20
to

Also the Kotlin language and runtime might suffer from
not enough "DIRECT STYLE" and even ignoring Doug Leas
java.util.concurrent.Flow, devlivering some bloated

redundant nonsense I speculate from glossing over it.
Flow has an interesting history. And all the new JDK 21
integrate HTTP server and HTTP client make use of

the interfaces bundled by the class Flow. But I am
tapping into it via ordinary InputStream and OutputStream.

Reactive Streams started as an initiative in late 2013
between engineers at Netflix, Pivotal and Lightbend.
Reactive Streams were proposed to become part of
Java 9 by Doug Lea, leader of JSR 166 as a new Flow
class that would include the interfaces currently
provided by Reactive Streams.
https://en.wikipedia.org/wiki/Reactive_Streams

Mild Shock schrieb:

Mild Shock

unread,
Feb 21, 2024, 6:43:51 AMFeb 21
to
The struggle of cloud world domination is real:

They stole the golang syntax for send and recieve?
https://ballerina.io/why-ballerina/concurrent/

BTW: The original Tchaikovski's Swan Lake is here:

Tchaikovski's Swan Lake that was broadcasted
during August Coup in all Soviet television (collapse of USSR)
https://www.youtube.com/watch?v=Tj2c6vJvyPA

So ballerina.io wants to see Google golang collapse,
because its too Russian (founder Sergey Brin is Russian).

Ok, enough galopping horses.

LoL
0 new messages