r/haskell • • 5h ago

announcement Experimental Dependent Types in Haskell Fork

14 Upvotes

Hey all!

Today I’m releasing my fork of GHC with -XDependentTypes. You can try it in the browser or walk through the examples.

I figured that if the slop cannon could help with the Riemann hypothesis, it could handle Dependent Haskell. And it did!

To see what the fork could do, I had Gemini 4 Neon port Programming Language Foundations in Agda to Dependent Haskell. Thanks to the GHC Wasm backend, you can work through the 25-chapter book directly in your browser. It even has an Agda mode built on my work on valid hole fits. Leave a hole in a proof and a hole-fit plugin can suggest what goes there.

There are examples of type-directed JSON encoding without type families, typed SQL schemas and joins, and Servant-style routing. You can select your monad transformer stack at runtime! The walkthrough also covers type-level case and lambdas, and linear protocols.

My goal is to build hype around dependent types in Haskell and show how much of the design is already there in the proposals. I’m releasing this as an experimental fork. I don’t plan to upstream it myself, though the GHC team is welcome to use it.

If you want to try it in your own project, there’s a dependent-base library. You can get it through dependent-hackage, an overlay along the lines of head.hackage. It also carries patches for tools like Fourmolu that need to understand the new syntax.

There’s even an observational equivalence plugin. Say you have a dependently typed implementation and a fast path written in ordinary Haskell. You can ask QuickCheck to look for inputs where the two disagree. If it finds one, you get a counterexample. If the tests pass, the result is only as strong as the generators and tests you chose.

Validation

The two main users so far have been the PLFH book and my PiTA library. The book turned up compiler bugs and showed where writing proofs was awkward. PiTA extends equality-constrained tree automata with dependent types and uses them to search for valid hole fits. Two plugins also exercise GHC’s internals: the observational equivalence plugin and a typed-hole proof helper.

I assume the implementation is full of holes (typed holes even) and bugs, but those can be fixed. I've run a sweep of Stackage and most packages compile, barring some minor shims for GHC 10.1 compatibility. Some minor compiler issues are being fixed as well.

Development notes

The initial work was done mostly by GPT-6.2 Astra managing a team of GPT-6.2 Sol agents. After I ran out of usage and resets, Gemini took over the compiler work with a team of Gemini 4 Carbon models. Both teams used their native harnesses, with some additional skills based on Well-Typed blog posts, anti-slop and humanizer skills for writing, and an internal agentic engineering plugin at DPella AB. Claude worked on PiTA and turned up several compiler issues.

I based the prompts on GHC proposal #378, the Serokell roadmap, and Richard Eisenberg’s thesis, papers, and old GHC branch.

The compiler, book, and PiTA work came to about 37.1 billion tokens in total, roughly 98% of them cache reads. At public API rates, the estimate came to around $16k. I ran it all on subscriptions, with some help from three banked resets, OpenAI’s generously timed billing bug, and Gemini’s Thanksgiving reset. So no need for a GoFundMe!

Acknowledgements

Thanks to Richard Eisenberg for proposal #378, his thesis, and the old GHC branch that gave us a place to start. Thanks to Vladislav Zavialov, Andrei Borzenkov, and the rest of the Serokell team for the roadmap and years of work on GHC, and to everyone who wrote and reviewed the other proposals we drew on.

Thanks to Philip Wadler, Wen Kokke, and Jeremy G. Siek for PLFA. Having a book full of proofs written for another language was a great way to find out where our compiler fell short.

Thanks to Cheng Shao, Norman Ramsey, and the other GHC Wasm contributors for making it possible to try this in a browser. Thanks to Jules (@analytichegel on Twitter) for the observational equivalence idea behind the QuickCheck plugin.

Thanks to Mercury for ghc-persistent-worker. With a few tweaks, it made those repeated incremental GHC builds a lot faster! And thanks to Andrea Bedini and IOG for Foliage, whose package metadata format we use in dependent-hackage.

Thanks for reading! I hope you get a chance to play around with it. If you find a bug, please file an issue on the fork. I’d love to see what people try with it, and I hope this builds some excitement for getting dependent types into GHC itself.


r/haskell • • 15h ago

The Bowling Game - From Imperative to Functional Programming - Part 4

Thumbnail fpilluminated.org
9 Upvotes

r/haskell • • 17h ago

[ANN] Distributed consensus library and ecosystem with built-in DST

27 Upvotes

Hey all,

Over the past year, I have been working on an implementation of the Raft consensus algorithm in Haskell, which allows for distributed consensus. In particular, using Raft, one can create a distributed, fault-tolerant state machine. The library has been released on Hackage under the name raft-consensus. Bring your own networking and persistence layer!

Raft is tricky to get right. To ensure that the library works correctly, and respects the properties of the algorithm in practice, even under faults such as crashes and network partitions, I leveraged a technique called deterministic simulation testing (DST), using io-sim as the foundation. io-sim is pure awesomeness that should be used more.

While building out examples, I noticed other ecosystem holes that resulted in more packages. Testing the linearizability of client requests required building a simple linearizability checker: linearizable. Another piece of technology that came from this project is a generic and performant implementation of write-ahead logs via a new wal package.

Finally, in order to make it as easy as possible to build a replicated state machine in practice, I built two adapter packages:

I feel relatively confident in releasing this stuff now because, over the past week, I’ve been working on a demo: distributed software transactional memory. This program looks just like stm, but running over multiple computers.
Right now it’s just a demo, but it shows how freaking cool distributed state machines can be.

My goal, since I started helping with maintenance of Cloud Haskell, has been for Haskell to become a solid choice for distributed systems. We’re now one step closer to that reality.

If you’re interested in this stuff, I would love to get your input on this and collaborate. Development for all of this is happening here: GitHub - LaurentRDC/distributed-consensus: Haskell implementation of distributed consensus protocols with built-in support for deterministic simulation testing · GitHub