Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Last active February 8, 2026 21:14
Show Gist options
  • Select an option

  • Save danidiaz/f170230aa193be328601d24915e42a45 to your computer and use it in GitHub Desktop.

Select an option

Save danidiaz/f170230aa193be328601d24915e42a45 to your computer and use it in GitHub Desktop.
{-# LANGUAGE UnliftedDatatypes #-}
{-# LANGUAGE GHC2024 #-}
{-# OPTIONS_GHC -Wincomplete-patterns #-}
module Main where
import Data.Kind
import GHC.Exts
import Data.Void
-- Unlifted types
--
type Branchy :: UnliftedType -> Type
data Branchy (e :: UnliftedType) =
MkBranchy e
| MkAnotherBranchy Int
-- deriving not possible because of the UnliftedType field
type MyUnit :: UnliftedType
data MyUnit = MkMyUnit
-- deriving not possible
type MyVoid :: UnliftedType
data MyVoid
-- deriving not possible
branchy1 :: Branchy MyUnit
branchy1 = MkAnotherBranchy 0
branchy2 :: Branchy MyVoid
branchy2 = MkAnotherBranchy 0
main :: IO ()
main = do
case branchy1 of
MkBranchy MkMyUnit -> putStrLn "foo"
MkAnotherBranchy _ -> putStrLn "foo"
case branchy2 of
-- compiler is smart enough to know one branch is impossible
MkAnotherBranchy _ -> putStrLn "foo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment