hn.today

Making a GTK application in Haskell, part 1

floreal.tech109 points21 comments
Screenshot of Making a GTK application in Haskell, part 1

A step‑by‑step guide demonstrates building a GTK 4 todo‑list desktop app in Haskell using libadwaita for GNOME styling and haskell-gi to generate bindings. It argues that combining Haskell’s pure domain logic with GTK/Adwaita yields a responsive, accessible UI that follows GNOME HIG, including runtime recoloring for light/dark themes. The setup centers on creating an Adw.Application for resource management and wiring a runtime loop that dispatches messages to an update function; this pattern keeps UI rendering separate from domain mutations and side effects.

Concrete specifics include a model‑view‑update style: messages like Add and SetDoneStatus are handled by update which returns (newModel, effects), with a helper that only emits a Save effect when todos actually change. Examples show GHCi interaction to illustrate effects firing. The view composes widgets (Box, ListBox, EntryRow, ActionRow, Clamp, ScrolledWindow, ToolbarView) and exposes a view :: (Message -> IO ()) -> Model -> IO Gtk.Widget function. Dispatch uses GLib.idleAdd to enqueue steps that read an IORef model, apply update, write back, and set window content via Adw.applicationWindowSetContent. The result is a working window with an input and a couple of tasks; further features are promised in Part 2.

Read on floreal.tech21 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.