Anybody using GHC2021

Note that this is actually new behavior in GHC 9.4: In 9.2, you get an actual error instead of a warning when trying to pattern match on a GADT with GHC2021:

Test.hs:7:5: error:
    • A pattern match on a GADT requires the GADTs or TypeFamilies language extension
    • In the pattern: T
      In an equation for ‘foo’: foo T = 5
  |
7 | foo T = 5
  |     ^

This was changed in !7042, see the linked #20485 for the motivation.

But it is indeed surprising that you can now use GADTs without enabling them, ie this compiles without any warnings or errors in GHC >=9.4:

{-# LANGUAGE Haskell2010 #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GADTSyntax #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# OPTIONS_GHC -Wall #-}

data T a where
  T :: T Int

foo :: T a -> a
foo T = 5

I wonder whether this is actually intended :thinking: EDIT: I commented on the issue linked above: #20485: Pattern matching on GADT pattern synonyms · Issues · Glasgow Haskell Compiler / GHC · GitLab

EDIT 2: I got pointed to this upstream ticket discussing whether it should be changed that one can define arbitrary GADTs without GADTs: #21102: GADT accepted without -XGADTs · Issues · Glasgow Haskell Compiler / GHC · GitLab

6 Likes

Yes, enabling GADTSyntax and ExistentialQuantification is enough to define and use GADTs. I regard it as a bug in GHC2021 that it included both but not GADTs. Unfortunately it’s not obvious of the best way to fix it since MonoLocalBinds isn’t included either, and enabling it is non-backwards-compatible.

I’m hoping we can resolve this in the next GHC20xx revision (see https://github.com/ghc-proposals/ghc-proposals/blob/51a0c9c4467f9cf3173ba06a987cce501ea242f0/proposals/0000-ghc2023.rst#why-add-gadts-and-monolocalbinds although GHC2023 didn’t happen).

2 Likes

I don’t think GADTs are stable enough to be in the next GHC202X. There have been breaking changes as recently as 9.6.1: 2.1. Version 9.6.1 — Glasgow Haskell Compiler 9.6.2 User's Guide

Edit: I guess it is just the combination of GADTs and Type Families, so perhaps the Type Families are the unstable part:

Record updates for GADTs and other existential datatypes are now fully supported.

[…]

A side-effect of this change is that GHC now rejects some record updates involving fields whose types contain type families (these record updates were previously erroneously accepted).

The next most recent breaking change was in 9.0.1:

GADT constructor types now properly adhere to The forall-or-nothing rule.

2.1. Version 9.0.1 — Glasgow Haskell Compiler 9.0.2 User's Guide, which is also not that long ago yet.

2 Likes

If it had been up to me, I might have included GADTSyntax but not ExistentialTypes/GADTs in GHC2021. But given that the de facto situation is that GADTs are supported in GHC2021, I would be tempted to continue to include them, because it would send a misleading signal to remove them now. I don’t think inclusion in GHC20XX should mean that the extension is necessarily completely stable.