{"slug": "tweag-beat-me-to-a-pubgrub-implementation-with-ai", "title": "Tweag beat me to a PubGrub implementation with AI 😅", "summary": "A Haskell developer built a PubGrub dependency solver for cabal-install-style version solving, splitting the work into a generic `pubgrub` package polymorphic over a `Domain v` type and a separate `pubgrub-cabal` package, after spending roughly two months on how to represent package flags. The developer said this was the first project where they made serious use of Anthropic's Claude from the start, using it to understand the algorithm, write tests, and learn the context of answer set programming and CDNL, and published benchmark and showcase reports comparing the solver against cabal-install's, including improved failure messages for cases such as aeson 2.3.1.0 with hlint 3.10. The work matters as an early account of AI-assisted development on a nontrivial constraint-solving problem and as a test of whether PubGrub can match cabal-install's dependency-version solving.", "body_md": "Oh, hi!\n\nyes, that’s me. I don’t think “getting there” first is an accomplishment really, and I am only happy to see someone working on the same problem. I have actually started working on PubGrub, only one day a week, in June. The commits only reach September because at some point I decided to start from scratch.\n\nThis was the first project where I made serious use of Claude from the start, and I have to say it had turned in a long journey. I also used it to understand the algorithm, and write tests but also to understand the more general context of answer set programming and CDNL<sup>[\\[1\\]](https://discourse.haskell.org#footnote-61015-1)</sup>. I wasn’t very familiar with the subject and I don’t think I could have pulled this off without the assistance.\n\n[@brandonchinn178](https://discourse.haskell.org/u/brandonchinn178) I love how crystal clear your implementation is, but I think we have solved quite different problems. From the start, I wanted to see if PubGrub could be used to do the same dependency-version solving that cabal-install does, and, in that case, whether it could offer better failure messages. To be able to compare apples to apples, my implementation had to at least account for pre-existing vs source packages and flags. Everything I could find about PubGrub only used version ranges, so I was in uncharted territory.\n\nDealing with pre-existing/source packages I thought wasn’t going to be too hard in theory since predicates over a sum-type are products of predicates (e.g. `Either a b -> Bool ~ (a -> Bool, b -> Bool)`; but choosing the right representation for the terms wasn’t obvious. The dependencies of pre-installed packages are exact and do not use versions, so it’s easier to model a version range directly as a set.\n\nDealing with flags instead was a huge problem for me, and I am still not quite sure if I got it right<sup>[\\[2\\]](https://discourse.haskell.org#footnote-61015-2)</sup>. The problem was how to represent flags. They can be separate variables or they can be buried into the version variable. If they are separate variables, they cannot be completely independent from the version, because `tasty +unix` does not quite make sense if the chosen version of `tasty` does not declare the `unix` flag. If they are buried into the version, then ordinary version ranges are no longer expressive enough, and a naive extension is not closed under the set operations required by PubGrub. I must have spent two months on this.\n\nEventually I decided that I could not work to understand PubGrub and to extend it at the same time so I decided to split the general algorithm from anything that has to do with cabal. In my [pubgrub](https://hackage-content.haskell.org/package/pubgrub) the solver is polymorphic over a `Domain v`, whose variables have type in `ValueOf v`, and whose sets (` SetOf v`) are constrained to have a set algebra `SetOps`. The specialisation of this to cabal packages lives in a different package [`pubgrub-cabal`](https://hackage-content.haskell.org/package/pubgrub-cabal).\n\nIf you are keen to know how pubgrub compares to cabal-install’s solver, I invite you to look at the [benchmark](https://github.com/tweag/pubgrub-hs/blob/main/docs/reports/benchmark.md) and the [showcase](https://github.com/tweag/pubgrub-hs/blob/main/docs/reports/showcase.md). This is an example:\n\n```\nNo solution for aeson ==2.3.1.0 and hlint ==3.10: base is\n    pinned to 4.21.2.0 (installed).\nNo version of deriving-aeson suits hlint >=3.4.1 unless aeson >=1.3 && <2.3.\n\nBecause deriving-aeson >=0.2 && <0.2.4 depends on aeson >=1.3 && <1.5 and\n    deriving-aeson >=0.2.4 && <0.2.5 depends on aeson >=1.4.7.0 && <1.5,\n    deriving-aeson >=0.2 && <0.2.5 requires aeson >=1.3 && <1.5.\nAnd because deriving-aeson >=0.2.5 && <0.2.7 depends on aeson >=1.4.7.0 && <1.6\n    and deriving-aeson >=0.2.7 && <0.2.8 depends on base >=4.12 && <4.16,\n    deriving-aeson >=0.2 && <0.2.8 requires aeson >=1.3 && <1.6 or\n    base >=4.12 && <4.16.\nAnd because deriving-aeson >=0.2.8 && <0.2.9 depends on aeson >=1.4.7.0 && <2.2\n    and base is pinned to 4.21.2.0 (installed), deriving-aeson >=0.2 && <0.2.9\n    requires aeson >=1.3 && <2.2.\nAnd because deriving-aeson >=0.2.9 depends on aeson >=1.4.7.0 && <2.3 and\n    hlint >=3.4.1 depends on deriving-aeson >=0.2, hlint >=3.4.1 requires\n    aeson >=1.3 && <2.3.\nSo, because aeson ==2.3.1.0 and hlint ==3.10 are requested, version solving\n    failed.\n```\n\nI took a break but I am not quite done with the package I think.\n\nThanks [@hasufell](https://discourse.haskell.org/u/hasufell), I will not be discouraged. [@brandonchinn178](https://discourse.haskell.org/u/brandonchinn178) has been very gentle with his words but I wasn’t quite expecting the first discussion about my package to be on “whether we should ignore it”. With respect to the documentation, the Haskell community has always been so welcoming of packages with no documentation, that it surprises me a little to receive criticism when my package even has a tutorial . Jokes aside, I know the documentation is not great, I still have work to do to improve it.\n\n[@brandonchinn178](https://discourse.haskell.org/u/brandonchinn178) I would love to exchange ideas on PubGrub. It makes me happy to read that you intend to use it. Please report any issue or feedback! Also don’t forget the code is also yours under the BSD-3 license. Read it, copy it, steal it. I genuinely hope you can get some value out of it in one way or another.", "url": "https://wpnews.pro/news/tweag-beat-me-to-a-pubgrub-implementation-with-ai", "canonical_source": "https://discourse.haskell.org/t/tweag-beat-me-to-a-pubgrub-implementation-with-ai/15253#post_12", "published_at": "2026-12-04 09:31:26+00:00", "updated_at": "2026-12-04 09:43:01.715544+00:00", "lang": "en", "topics": ["ai-tools", "developer-tools", "ai-agents"], "entities": ["Tweag", "PubGrub", "cabal-install", "Claude", "Anthropic", "Haskell", "pubgrub", "pubgrub-cabal"], "also_reported_by": [], "takeaway": "Splitting a solver into a generic `pubgrub` package polymorphic over a `Domain v` with a `SetOps` set algebra and a separate `pubgrub-cabal` specialization let the developer extend PubGrub to cabal packages, flags and pre-existing packages without modifying the core algorithm.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/tweag-beat-me-to-a-pubgrub-implementation-with-ai", "markdown": "https://wpnews.pro/news/tweag-beat-me-to-a-pubgrub-implementation-with-ai.md", "text": "https://wpnews.pro/news/tweag-beat-me-to-a-pubgrub-implementation-with-ai.txt", "jsonld": "https://wpnews.pro/news/tweag-beat-me-to-a-pubgrub-implementation-with-ai.jsonld"}}