Last active
January 24, 2026 09:45
-
-
Save LSLeary/7165377d1a28bf76aa4c0aae189a6968 to your computer and use it in GitHub Desktop.
Match on type
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 | |
| GHC2021, PatternSynonyms, ViewPatterns, ExplicitNamespaces, GADTs | |
| #-} | |
| module Is (pattern Is) where | |
| -- base | |
| import Type.Reflection | |
| import Data.Type.Equality (type (~~)) | |
| pattern Is | |
| :: forall {k} {l} (a :: k) (b :: l) | |
| . Typeable a | |
| => a ~~ b | |
| => TypeRep b | |
| pattern Is <- (eqTypeRep (typeRep @a) -> Just HRefl) | |
| where Is = typeRep | |
| _test :: forall {proxy} a. Typeable a => proxy a -> String | |
| _test _ = case typeRep @a of | |
| Is @Bool -> "bool" | |
| Is @Double -> "double" | |
| _ -> "dunno" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment