[ANN] Experimental Dependent Types in Haskell Fork

Hey all!

Today I’m releasing my fork of GHC that has -XDependentTypes:

I figured that if the slop cannon could solve the Riemann hypothesis, it could handle dependent Haskell. And it did!

To showcase what the fork could do, I had Gemini 4 Neon port Programming Language Foundations in Agda to using dependent Haskell instead, and thanks to the excellent GHC WASM backend, you can play around with it in the browser directly. It even includes an Agda mode based on my valid hole-fits (and a hole-fit plugin), so you can get help with writing your proofs.

It also includes real world Haskell examples like Type-directed JSON encoding without type families, typed SQL schemas and joins, and Servant-style routing. You can now select your monad transformer stack at runtime!

Note: The goal here is not to upstream this (though the compiler team is welcome to it), but to build hype around dependent types in Haskell and to show that Dependent Haskell is already possible in terms of proposals and extensions. We just have to build it!

It includes a dependent-base and a playground for you to get started directly, available via a head.hackage like overlay called dependent-hackage for any projects (e.g. fourmolu needs some AST changes). There’s even an observational equivalence-based type-checker plugin, which lets you “prove” that your non-dependently typed fast path matches the dependently typed implementation using QuickCheck (though only up to the generators and generated tests ofc).

Validation

The only consumers so far have been the PLFH book linked above (which turned up compiler bugs and showed where writing proofs was awkward), and my PiTA library (an extension of ECTAs with dependent types, used for valid hole-fits). There are also two plugins (observational equivalence and a typed-hole proof helper), that exercise some of the internals. I assume that the implementation is full of holes (typed holes even) and bugs, but those can all be fixed in good time. 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 with a team of Gemini 4 Carbon models. Both used their native harnesses, but with some additional skills based on Well-Typed blog posts, anti-slop and humanizer for writing, and an internal agentic-engineering plugin at DPella AB. Claude was also involved in writing the PiTA library, and surfaced multiple 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, that would have cost around $16k. I ran it all on subscriptions, with some help from three banked resets and OpenAI’s generously timed billing bug, as well as a Gemini Thanksgiving reset. So no need for a GoFundMe!

Acknowledgements
Some thanks are definitely in order:
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, and to Mercury for ghc-persistent-worker. With a few tweaks, it made those incremental GHC builds a lot faster! Andrea Bedini and IOG for Foliage, whose package metadata format we use in `dependent-hackage`.

And to you, thanks for reading! I hope you have a chance to look at it and play around with it, and report any issues you find on the repo. Hopefully this inspires some hype and we can get dependent types in GHC itself soon!

27 Likes

Well done @Tritlo :clap: can’t wait to hear what @int-index has to say about this and the community takes it.

2 Likes

Same!

As written above, this is not intended to be a PR to HEAD, mostly a tool for me to understand what we could be doing in dependent Haskell. My favorite is probably the type-directed JSON encoding, without any typeclass stuff. It’s so clean!

toJson :: foreach (a :: Type) -> a -> String
toJson a v = case a of
  Int         -> show v
  Bool        -> if v then "true" else "false"
  [Char]      -> "\"" ++ v ++ "\""
  Maybe Int   -> maybe "null" show v
  (Int, Bool) -> "[" ++ show (fst v) ++ "," ++ toJson Bool (snd v) ++ "]"
  _           -> "\"<opaque>\""
3 Likes

If we had some string interpolation this could indeed become clean instead of this ++ eyesore.

2 Likes

I haven’t read the code not tested it yet, but this looks like a lot of work!

If the approach is good and follows the approved proposals, is there a way to turn this giant diff into small, reviewable GHC PRs? Discarding everything seems wasteful.

Nice experiment, and it’s cool that I can try it in the browser!

Is there a more technical write-up on the implementation techniques and limitations? At the moment, I don’t understand what is and isn’t supposed to work.


For example, consider

{-# LANGUAGE DependentTypes #-}

module Playground where

f :: forall a. a -> a
f x = x

n :: f Int
n = 10

This is accepted with the message

Ok, module typechecked and loaded into GHCi (-XDependentTypes).

That’s impressive: I’ve been able to use a term-level function f (which happens to be the identity function) in the type signature of n.

But let’s take a closer look. The call site f Int instantiates a to Type, so presumably I should also be able to write

-- import Data.Kind (Type)

m :: f @Type Int
m = 10

Mysteriously enough, this fails:

/tmp/work/Playground.hs:13:6: error: [GHC-68947]
    • No checked equations are available for ‘f’ in a type.
      Match a constructor-valued argument with one clause per constructor, using variables or wildcards for its fields.
      Build the result from constructors, bound variables, or fully applied functions with checked equations.
      In a recursive call, pass a field of the matched argument directly.
      Bind any other arguments with variables and pass them unchanged in recursive calls.
    • In the type signature: m :: f @Type Int
   |
13 | m :: f @Type Int
   |      ^

I get a similar message if I specialize f at the definition site:

f :: Type -> Type
f x = x
/tmp/work/Playground.hs:8:1: error: [GHC-68947]
    No checked equations are available for ‘f’ in a type.
    Match a constructor-valued argument with one clause per constructor, using variables or wildcards for its fields.
    Build the result from constructors, bound variables, or fully applied functions with checked equations.
    In a recursive call, pass a field of the matched argument directly.
    Bind any other arguments with variables and pass them unchanged in recursive calls.
  |
8 | f x = x
  | ^

I can’t tell whether it’s an overeager check or a symptom of a deeper issue.

10 Likes

GHC’s AI policy requires that the author understands and can defend the patch: Making sure you're not a bot!

4 Likes

LLMs are impressive. I didn’t think we could make GHC errors worse.

On a serious note, I appreciate the sentiment that we shouldn’t merge this. I think it’s a good analogy for the LLMification of our world.

Using an LLM to do this like this implies -XDependentTypes is some goal or end state. If we get there, we win! Who cares how?

Nah..it’s the beginning. LLMs are garbage as beginnings. Let’s lay the foundation properly. We can’t imagine what people will build on 10y of Dependent Haskell.

7 Likes

Good point! And, admittedly, it’s way too early to talk about merging. It’s just that reading “I implemented dependent Haskell” followed by “it’s not meant to be merged upstream” was a bit of an emotional rollercoaster.

2 Likes

Very impressive! Kudos to you and Neon.

4 Likes

Is building hype really going to get us closer to an implementation? Done in this way I think there’s even a good chance that people (like me) are put off from continuing their work on Dependent Haskell.

3 Likes

I think it is all slop honestly, I wouldn’t risk it or even look at it. As I said the GHC compiler team is free to use this any way they want but yeah, I’m not going to defend any of it. The aim here is more to have something to play around with, for people like me who lack the “dependent Haskell compiler” component in their head. I need concrete code that I can edit and “run” (if just in a vibecoded implementation) to understand all the stuff going on in the proposals

5 Likes

I’m sorry if that is the case. Like stated above, the aim here is to have something to play around with, to get a “feel” for it. People who are actually familiar with the proposals etc. won’t need this, but someone like me (a bit out of the loop) do!

These are great questions. I’ll need to have a proper look at what is going on before I answer.

How so? Are you dissuaded because there’s a half-assed solution that will never reach mainstream GHC?

4 Likes

I laughed when I saw this :joy: Amazing work @Tritlo

4 Likes

If you’re really interested in my feelings, I suggest you do so in a less antagonistic manner.

3 Likes

Thank you for the experiment. I’m duly hyped, being a GHC user and, in particular, noting that writing proofs has become much easier lately thanks to LLMs, so Dependent Haskell and other extensions that integrate correctness proofs into Haskell may let us write fully verified Haskell code at a scale we never dreamed of (unless, e.g., specification-writing/type-signature-writing becomes the new bottleneck, but that’s a new fascinating question on its own).

OTOH, I can speculate how people toiling on GHC daily may be less enthusiastic. Dependent Haskell and any other lofty visions surely matter for career choices. It may not be the same for ongoing work, where you found more errors last week than you fixed and you are not sure how many you introduced, and that’s in good weeks, in bad you spend all the time reviewing potentially valuable contributions wrapped in copious AI slop, battling with the (AI-cracked) infrastructure, performing release chores, etc. I’d expect the daily motivation not to be the lofty research hype but the grisly doggeness of the kind a) “but there is no other way” or b) “but at least I’m relatively competent at this and somebody has to do it”. Then it takes some thick skin not to become defensive when you drop an experiment suggesting on the surface that a) maybe none of this hard work matters because Singularity is nigh at hand (or at least AI that codes everything directly in assembly with full proofs) and b) maybe others could do the same hard work in 0.0001 time with different tools.

That’s not even touching the ethical and existential issues related to LLMs and the enormous groups of interest remodeling our world around them with no plan B.

4 Likes

The detail proposal of InterpolatedStrings was already Acceped and it is waitng for Implementation!
Technical ammedement about efficient specialization is also accepted.

2 Likes

I see the point, but I’m not introducing anything new here. This is what came out from publicly available tools (albeit with a subscription) and around two weeks of work on the side (mostly waiting on GHC rebuilds). I agree that things are moving fast, and I myself feel dejected sometimes. But the world is moving on with or without us, and the only thing we can do is adapt and overcome.

3 Likes