[ANN] Experimental Dependent Types in Haskell Fork

Or the secret third thing: Go the same speed as before. Life isn’t always a competition :slight_smile: and irl i don’t have performance reviews with a dollar-coated carrot coercing me to only use AI

9 Likes

That’s great! Not all of us are as lucky.

1 Like

LLMs seem to have brought a lot of joy to many programmers, allowing them to prototype things that were previously out of reach. I personally don’t feel the same, but I’m excited for my colleagues who do.

However, I would advise caution against the “you’ll be left behind” narrative. While it is a reality for many in the workplace, I still believe that Haskell is the main language of choice for craftsmen! And that’s something we should celebrate too.

9 Likes

Why is this repo still called GHC and why does it contain all kinds of stale GHC docs? For example, it tells people to go to the #ghc on libera.chat. I feel like it would be best to rename the fork. XEmacs got a new name too when it forked. It isn’t fair to direct questions about this code that nobody understands, to the GHC team.

I certainly hope so. I’m not convinced.

Regarding the link with the Riemann hypothesis : was Dependent Haskell not known to be implementable? I ask as someone who knows nothing about this.
Knowing that it is possible, without understanding how completely, is still valuable.

2 Likes

because it’s a fork based off of main! It’s still all GHC code, and just adds a new -XDependentTypes language extension and machinery. It’s not intended as a separate project for people to depend on.

Edit: sorry I realize now that fork has a different connotation as well. I mean fork as in “it is a fork on GitHub” not as “here’s a new parallel project”. Hope that clarifies it.

It’s not as deep a comparison as that. Back in ~2024 people weren’t convinced that LLMs were “smart” enough to handle dependent types, but the RH and other recent work has shown that it’s quite capable of juggling the relevant bits.

1 Like

I think the question was if your work, e.g., proves consistency of the Dependent Haskell design or any new property of the system or offers some quantitative insights, e.g., an estimate how much new type-checker code is likely to be needed before the project is fully implemented and vetted.

2 Likes

Ah I got it.

it’s ~39k net lines of code in the typechecker (compiler/GHC/Tc/**), ~3k lines of code in the renamer (Rename/**), ~7k in Core/** and about ~6k lines spread around for the rest (Iface, interface bridges, HsToCore, driver, etc.), for a total of ~55k.

I was never asked to make a decision on how anything should work, although I did specify that any ambiguity should be resolved by looking at the proposals, papers, and default to Agda behavior otherwise.

4 Likes

Oh the “rl” in “irl” there is real life as in MY real life. I still have a job so I do get to use a lot of agentic programming. It’s..fine.

There is no human written technical write up so far, but there are a few MDs in the fork repo covering the implementation and current boundaries:

As for the examples: good news! Both are compiler bugs rather than deep theoretical limitations, and are now fixed (make sure to force reload to get the latest WASM!)

  1. m :: f @Type Int is a bug. f :: forall a. a -> a gets certified into a closed source-equation type family, but the term-head dispatch path bails out too eagerly. Fixed!

  2. f :: Type -> Type; f x = x was an overly restrictive check on Type -> Type definitions. Fixed!

5 Likes

Cool, I’ve tried the updated version and it works! Let’s continue.

Now consider

{-# LANGUAGE DependentTypes #-}
module Playground where

import Prelude.Dependent (Nat(Succ, Zero), Fin(FZ, FS), U)
import Data.Kind (Type)

idAt :: forall (b :: Nat %U -> Type). b Zero -> b Zero
idAt x = x

u :: Fin (Succ Zero)
u = idAt @(\x -> Fin (Succ x)) FZ

This loads just fine, instantiating b to a lambda \x -> Fin (Succ x).

But it stops working if I bind this lambda to a name, so

u :: Fin (Succ Zero)
u = idAt @finSucc FZ

finSucc :: Nat -> Type
finSucc = \x -> Fin (Succ x)

fails with

/tmp/work/Playground.hs:14:1: error: [GHC-68947]
    No checked equations are available for ‘finSucc’ 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.
   |
14 | finSucc = \x -> Fin (Succ x)
   | ^^^^^^^
3 Likes

this is now fixed, and a bunch of other deviations from the proposal as well.

more patches incoming overnight!

on a positive note, this means that LLMs haven’t quite taken our jobs yet!

8 Likes

At this point, my guess is the LLMs are doing short term fixes. Gradient descent to satisfy the goal (int-index’s counterexamples). Gradient descent leads to local optima..

3 Likes

I tried a few more examples in the play ground, and it seems quite inconsistent and unpredictable what will be accepted.

foo :: forall a. Maybe (id a) -- accepted
foo = Nothing
foo :: forall a. id (Maybe a)
/tmp/work/Playground.hs:25:21: error: [GHC-70565]
    • Cannot evaluate ‘id’ in a type.
        The argument must be a closed literal of one of these kinds: Natural, Char, Bool, List Natural, List Char, List Bool.
    • In the type signature: foo :: forall a. id (Maybe a)
                  ^^^^^^^^^
foo :: forall a. Maybe (id (id a))
/tmp/work/Playground.hs:25:32: error: [GHC-70565]
    • Cannot evaluate ‘id’ in a type.
        This argument is a type variable. Closed evaluation requires a known value.
    • In the first argument of ‘Maybe’, namely ‘(id (id a))’
      In the type signature: foo :: forall a. Maybe (id (id a))                         ^
foo :: forall a. Maybe (id id a)
/tmp/work/Playground.hs:25:25: error: [GHC-70565]
    • Cannot evaluate ‘id’ in a type.
        Expected 1 value argument, but got 2. Closed calls must be fully applied.
    • In the first argument of ‘Maybe’, namely ‘(id id a)’
      In the type signature: foo :: forall a. Maybe (id id a)
2 Likes

another one:

data T a where
  TB :: T Bool
  TI :: T Int

foo :: T a -> a
foo TB = False
foo TI = 0

t :: foo TB :~: False
t = Refl
/tmp/work/Playground.hs:15:6: error: [GHC-70565]
    • Cannot evaluate ‘foo’ in a type.
        /tmp/work/Playground.hs:15:6: fatal:
            cannot find object file for module ‘Playground’
            while linking an interpreted expression
    • In the first argument of ‘(:~:)’, namely ‘foo TB’
      In the type signature: t :: foo TB :~: False
1 Like

for sure, the hope is though that the current local optima is not too far away from the global one. But yeah needs a lot more love and checks, which is exactly why I’m sharing it!

1 Like

Can LLM code of this scale be iterated on to the point where it’s usable by humans going forward? I haven’t seen it (speaking as someone who gets to work with a giant LLM-maxxing Haskell codebase), and other people have echoed this same sentiment.

Can this changeset even be divided into readable stacked PRs with a coherent logical progression to them? That feels like a useful starting point to pursue even if the goal is to never merge this as it would help us read & grok the giant changeset without LLM assistance.

Because if iterating on GHC isn’t doable by a human with a text editor without an LLM..that’s a failure mode in my book.

1 Like

Is any of the problematic examples by chance an evidence that Dependent Haskell is, in fact, inconsistent? Given such a discovery its maintainers would have a chance to revisit the design earlier rather than later. Or could such examples be proposed? Could LLM iterate finding adversarial examples and for each either fix your fork or, maybe at some point, prove a gap or a surprising behaviour of Dependent Haskell as defined by its authors?

I’m not saying this was the purpose of your experiment, but that may be a way to benefit from its infancy-period failure modes. And if hundreds of tough examples all lead to improving the fork and none to finding a sharp edge in the design, we gain both a better prototype and more evidence the design is sound.

2 Likes