Functional style - examples

2015 … Boian Mitov

2017 … Glen Kleidon presented to Melbourne ADUG … @Glen_Kleidon2
Adopting a Functional programming approach in Delphi “.

I hope we might see a recording of it sometime, if it exists ( @Geoff ?)

https://www.adug.org.au/meetings/melbourne-meeting-april-2017/

2021 … I spoke to our Perth members, and then Melbourne, in an attempt to describe some basic Category Theory and the relation to FP.

2022 … Kevin Bond @drbond presented at Delphi Boot Camp 2022

“Delphi and functional programming using anonymous methods”

Unfortunately @Paul_McGee, We don’t have recordings prior to the start of COVID for Melbourne meetings.

Related to this query : SQL formatter library wanted

People might like to take a squiz at how the datatypes in Haskell are used in this library
to capture the structure of SQL statements.
source : queryparser/Query.hs at master · uber/queryparser · GitHub

Product types are like our Record and Class.
eg A single type might contain integer AND string AND enum.

image

Sum types (co-product types) are the opposite of product types.
eg A single type which is integer OR string OR enum.

‘Select r a’ and ‘Expr r a’ are type constructors.

Just like a generic type in Delphi, eg TSelect< R,A > or TExpr< R,A >
they need to be provided with two types in order to form a concrete type, like eg TExpr< string, string >

Rust vs current C++

Proposed C++

(and ditto for Delphi …)

Javascript … continuations (completion handlers ?)

These are asynchronous functions (like TTask, but returning a value) … that can be composed into further work to be performed, using that thread, without paying the cost of winding up a thread only to launch a new one to do the next step of the process.

These are Promises - the fetch() call returns a promise.

Promises have been around in Javascript for a long time, initially as a library but were added to the official Javascript around 2014.

I tried to implement something like this in Delphi, but the lack of Lambdas (arrow functions in JS) just made everything too verbose. The closest I got to this is my VSoft.Awaitable library (which is a wrapper over OmniThreadLibrary).

1 Like

I considered mentioning promises/futures … as opposed to our TFuture … but I wanted to keep it bite-sized, and am also no expert on javascript.

I have been accumulating material over the year that could be a talk called “Vocabulary” …

I have an idea that javascript has developed along a timeline with callbacks … then promises and futures … and then async/await.

I’ve seen that C# has co-routines, tasks, and async/await/yield. And completion handlers, I think?

And C++ has promises/futures and has been adding co-routines just now, which in typical C++ fashion at the moment looks like a mechanic upturned a shipping crate of tools onto a garage floor.

Some of it has been slowly congealing into a more uniform perspective, that I’m also trying to picture in Delphi terms, but I’m not there yet.

PS : I have only just recently realised we have the AIO library in Delphi that apparently implements greenlets (co-routines)

PPS : … and that there was a ‘Coroutine Pascal’ in the past.
PPPS : and ‘Garden Point Component Pascal’ Component Pascal

PPPS : I’d be very happy to hear much more about this stuff from anyone that felt like talking about it … it’s surely something Delphi can develop towards better in the future.

:rofl: :rofl: :rofl:

Do you know how many complex language features embarcadero have implemented in the last 10 years? The last ones were in 10.3 Rio.

I have advocated for language enhancements for many years - but always gets pushed to the back of the queue while they try to keep up with the constantly changing mobile dev tool chains. The reality is embarcadero simply do not have the resources to do this.

My original post was almost 6 years ago - you would think that a lot could be achieved in 6 years, but that isn’t what happened.

1 Like

Sure, I understand that.

The changes in C++20 and C++23 are pretty huge.
Gcc and Clang are seen as the major worldwide compilers, with Microsoft seen as a bit less in general.
Except Microsoft have already included all? many? of the newest features in their compiler.

C++Builder implements C++17. Dinkumware provided the standard template library … but has wound down its business now, I think. So they (Embarcadero) have a real issue there too.

I’m assuming things may come to a head at some stage … open-sourcing the Delphi and CB compilers ??
Or some step in that direction??
Surely it can’t just coast down to a stand-still …

Not sure if I’m going too low level for you… but I believe co-routines could be implemented with Fibers for some use cases anyway.

https://nullprogram.com/blog/2019/03/28/

From @Glen_Kleidon2 Melbourne talk this month, he was talking about a missing WriteAsync function in delphi. The actual IO could be handled by a IO Completion Port or using Overlapped IO. Once the Write call has been scheduled… the WriteAsync call would switch to/or create another fibre that is waiting on the IO port… which would then use SwitchToFiber to load back to code to continue the function that called WriteAsync. Sleep calls could be handled in a similar fashion - Using CreateWaitableTimer.

1 Like

I’m convinced that a lot can be done in six years. But it requires resources. If there are none, nothing will get done.

I wish they fixed the basics first, i.e.: TClientDataset is as broken now as it has always been.

Alex