{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreiacrlbnbyjcpg2pk2tc2rltcg6x4o3claf5zpwrh2lejqhibfr7te",
    "uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mikaaxt2eqc2"
  },
  "path": "/t/type-equality-in-gadt-typefamily-context/13876#post_5",
  "publishedAt": "2026-04-02T20:25:20.000Z",
  "site": "https://discourse.haskell.org",
  "textContent": "Here is a trick: instead of defining `Pop` with non-linear patterns in the equality case, you branch on a boolean equality test:\n\n\n    type family Pop n c where\n      Pop '[] _ = '[]\n      Pop (d ': n) c = If (d == c) n (d ': n)\n\n\nThen in the `pop` function you need to match on this boolean. From a `KnownSymbol` constraint, there is no way to do this safely AFAIK, so here is a way that defines the missing primitive `eqSymbol` using `unsafeCoerce`:\n\n\n    {-# LANGUAGE GADTs #-}\n    {-# LANGUAGE RankNTypes #-}\n    {-# LANGUAGE DataKinds #-}\n    {-# LANGUAGE TypeFamilies #-}\n    {-# LANGUAGE UndecidableInstances #-}\n\n    import Prelude\n    import GHC.TypeLits\n    import Data.Proxy\n    import Data.Type.Equality\n    import Data.Type.Bool\n    import Unsafe.Coerce (unsafeCoerce)\n\n    data N (l :: [Symbol]) where\n      NilN :: () -> N '[]\n      ConsN :: KnownSymbol x => Proxy x -> N l -> N (x : l)\n\n    type family Pop n c where\n      Pop '[]       _  = '[]\n      Pop (d ': n)  c  = If (d == c) n (d ': n)\n\n    pop :: forall c n. KnownSymbol c => N n -> Proxy c -> N (Pop n c)\n    pop (NilN ()) _  = NilN ()\n    pop l@(ConsN x n) c =\n     case eqSymbol x c of\n       STrue -> n\n       SFalse -> l\n\n    data SBool (b :: Bool) where\n      STrue :: SBool True\n      SFalse :: SBool False\n\n    eqSymbol :: (KnownSymbol c, KnownSymbol d) => Proxy c -> Proxy d -> SBool (c == d)\n    eqSymbol c d = case sameSymbol c d of\n      Just Refl -> unsafeCoerce STrue  -- can't solve (c == c) ~ True ???\n      Nothing -> unsafeCoerce SFalse\n\n    main :: IO ()\n    main = pure ()\n",
  "title": "Type equality in GADT/TypeFamily context"
}