Cover Image for Ben Hutchison: Direct syntax - Make Functional Programming in Scala Fun Again!
Cover Image for Ben Hutchison: Direct syntax - Make Functional Programming in Scala Fun Again!
Avatar for Melbourne Compose Group
Melbourne Compose is a monthly meetup for practitioners of typed functional programming, including the Haskell & Scala languages
Hosted By
5 Went

Ben Hutchison: Direct syntax - Make Functional Programming in Scala Fun Again!

Registration
Past Event
Welcome! To join the event, please register below.
About Event

Thursday July 17th, Ben Hutchison will lead a discussion about "Direct syntax - Make Functional Programming in Scala Fun Again!"

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
```

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.

Location
Kathleen Syme Library and Community Centre
251 Faraday St, Carlton VIC 3053, Australia
Avatar for Melbourne Compose Group
Melbourne Compose is a monthly meetup for practitioners of typed functional programming, including the Haskell & Scala languages
Hosted By
5 Went