Thursday Jul 17: Ben Hutchison on "Direct syntax - Make Functional Programming in Scala Fun Again!"

18 views
Skip to first unread message

Ben Hutchison

unread,
Jul 11, 2025, 12:27:00 AMJul 11
to Melbourne Compose Group
The next Melbourne Compose meetup is Thursday July 17th 6-8pm, at our usual venue the Kathleen Syme Centre, 251 Faraday St, Carlton.

Ben Hutchison will lead a discussion about "Direct syntax - Make Functional Programming in Scala Fun Again!" (rescheduled from June).

We'll study the example below, written as a classic for-comprehension and then again, in direct form.

The for-comprehension is burdened with unnecessary boilerplate code, and the if-statement requires noisy, meaningless else branch. The second version using direct syntax is akin to typical non-functional style, as we might see in an object-oriented or imperative language like C#. Did FP just reinvent imperative programming? ... or is there more to the story?

```
def fetchStoreRecord[F[_]: {Async as A, UUIDGen, Session}](id: Long): F[Unit] =
  for (status, optRecord) <- queryRecordServer(id)
      _ <- if status == 200 && optRecord.isDefined then
          for id <- newUUID
              _ <- saveRecord(id -> optRecord.get)
          yield ()
        else A.unit
  yield ()


def fetchStoreRecordDirect[F[_]: {Async, UUIDGen, Session}](id: Long): F[Unit] =
  async[F]:
    val (status, optRecord) = queryRecordServer(id).await
    if status == 200 && optRecord.isDefined then
      saveRecord(newUUID.await -> optRecord.get).await
```
https://gist.github.com/benhutchison/ef295940a19567360fc09b269a6d011e

We'll spend the session understanding what's going on in the above example.

This will take us down a rabbit hole to meet Effectful Values, a key idea in functional programming, and then on to the question of how to express compositions of them. And the rest is just syntax ;)

Arrive from 530pm for conversation & socialising, we'll begin the presentation around 630. We'll probably go for dinner on Lygon st afterwards .

As always, newcomers most welcome. Reach Ben on 0407 990 094 on the night if you have any issues finding the venue.

John Walker

unread,
Jul 18, 2025, 8:13:12 PMJul 18
to Melbourne Compose Group
Thanks for a great session Ben!!

A couple of follow ups:
With luck your frustration at the slow/lack of adoption direct syntax may be a little premature. Looks like there is a new entry level effects programming book where examples exclusively use direct syntax: listen for a minute or two from here ~ https://youtu.be/RVpXoeFQkjk?si=9kzMgQy-g6l2Drlc&t=2225

On effects in general there was  a great ZuriHack talk by Tom Ellis on the history of (Haskell) effect systems uploaded about a week ago: https://youtu.be/RsTuy1jXQ6Y?si=NSWkfjorse1W4fCZ

John

Ben Hutchison

unread,
Jul 18, 2025, 8:38:36 PMJul 18
to Melbourne Compose Group

Ah yes, thanks for the link, I wasn't aware of that book. There is interest in Direct style syntax at several places in the Scala ecosystem, but it's still scattered and non mainstream. 

To ZIO Direct specifically, there's something they don't mention in the podcast. It's close to abandonware. No commit for 2 years  ie Suitable for a point in time book, unsuitable for industrial use. 

There's also Kyo Direct. They use Dotty CPS under the hood. Not abandoned. They are reporting lots of issues and sending PRs. Healthy sign. 

And then there's Martin Oderskys Caprese. Like the Metro tunnel, should be available for use any time now 😝

-Ben

--
You received this message because you are subscribed to the Google Groups "Melbourne Compose Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to melbourne-compose...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/melbourne-compose-group/0f09ddce-07dd-427b-8956-704e94fb8d4en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages