Last active
February 8, 2026 21:14
-
-
Save danidiaz/f170230aa193be328601d24915e42a45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# 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