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 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