External Publication
Visit Post

[ANN] css-class-bindings library generates Haskell bindings for CSS classes

Haskell Community [Unofficial] April 7, 2026
Source

george.fst:

I’m curious why you chose to generate data constructors for IDs, instead of variables of a fixed type like you do for classes?

Using variables was the first idea to pop in my head, but I decided to put it aside because ids and classes exist in separate namespaces and merging them into one would require providing disambiguation logic such as a suffixes to avoid compilation errors.

george.fst:

Also, what’s your approach to parsing the CSS? An ID appearing in a position like *:not(#a) {} isn’t picked up, even though a class in the same place is.

It is folding a list of CSS tokens from css-syntax package with pattern matching. Class syntax is easy to catch and using something like attoparsec here is definitely overkill.

george.fst:

Wasm backend’s GHCI browser mode’s Template Haskell support isn’t able to read files.

What version of GHC are you talking about?

TH in 9.12.2 with WASM Backend works fine. includeCss is used in vpn-router. The project build is sealed with Nix. You should not have an issue with reproducing the results.

I fixed the bug you reported in v0.0.4.

I am curious how many ids do you expect on in an app you maintain?

As for me using id in CSS selectors seems as an anti-pattern, because:

  • ids are global and make composition of HTML components harder (sort of global variable in a classic programming language)
  • modern web development “single page app” do not need ids (the whole page is a view conditionally composed from other views). An exception is a migration of a legacy jquery-like project where injection places of “react” components are specified with ids, and this is not about styles. Modern CSS support layers feature expanding priority spectrum.

Discussion in the ATmosphere

Loading comments...