Skip to content

Instantly share code, notes, and snippets.

@LSLeary
Last active January 24, 2026 09:45
Show Gist options
  • Select an option

  • Save LSLeary/7165377d1a28bf76aa4c0aae189a6968 to your computer and use it in GitHub Desktop.

Select an option

Save LSLeary/7165377d1a28bf76aa4c0aae189a6968 to your computer and use it in GitHub Desktop.
Match on type
{-#
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