I made a native macOS Gleam Playground

A screenshot of the Gleam playground app I built, nicknamed Faff.

Last week was my second full week at the Recurse Center. It was great!

I gave a presentation for non-tech presentation hour. I spoke about Hatshepsut, my favorite Ancient Egyptian pharaoh. She used both male and female pronouns and in statues she was represented as male, female, and androgynous. I think it went well but I could have spoken for an additional 15 minutes, of course.

I also spun up a new app project and managed to get an MVP going. In order to learn Gleam, I wrote a macOS app in Swift! 💻

Gleam does not have a REPL, but it does have a friendly playground available. I find myself opening it frequently to try out some quick code – remembering syntax, trying a recursion approach, trying to pipeline multiple calls in order. 🛝

It's a great tool, but I lose old content easily and end up repeating myself. I ended up writing a Gleam playground app for macOS, nicknamed Faff after Gleam's branding pink of choice. I used Point Free's The Composable Architecture (TCA), which is an amazing framework for managing state in complex Swift apps. It is inspired by lots of functional ideas, primarily The Elm Architecture (TEA), but the PF guys are frequently making incredibly powerful updates to the library that change how construction of an app works and make me forget what I'm doing. All my TCA templates frequently need updates. 😅

One of Gleam's popular web frameworks, Lustre, is likewise inspired by TEA, and I thought writing this app in TCA would help get my mind into that kind of space. It was a good exercise, and I learned a lot.

  1. PF recently introduced SwiftSharing, a framework for managing shared state. Like all of their stuff, it's incredibly powerful and makes the language seem like magic, but there are slight syntax hiccups that frequently caught me up. And, unfortunately, the Swift compiler is not the greatest at type-checking, and sometimes struggles with PF's powerful typing, resulting in trash error messages. The TCA group on iOS Folks, a Slack outfit I belong to, is very helpful, though. I eventually managed to get a very simple system working using both UserDefaults (the most basic, relatively insecure key-value store available on Apple apps) and JSON file storage. It would take just a little bit of extra work to port this to proper persistence with a relational database.
  2. When I originally used TCA, I was used to passing sequences of events to one another to try to make each one pure and compact. It turns out, for performance, this isn't the current best practice. In fact, I had to read up on the latest performance recommendations. Specifically, it helps to offload shared computation to Reducer methods rather than exclusively use Actions.
  3. I am pretty bad at UI and UX ! I would love to get better. Maybe next week I can find someone at RC to help me with these things!
  4. I have a number of ideas to improve the app and make it usable by others. Right now it uses a hardcoded path reference to my local Gleam binary. I would prefer the app to download its own version of the Gleam compiler and keep it local. As I said earlier, I would also like to use proper database persistence for the Playground models.

All in all, a very fun exercise! Next week is the "hour of doing impossible things", though I think I will make it a week. By Friday I hope to have a basic Gleam web app live on the web. 🥅