{-# LANGUAGE ViewPatterns #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE AllowAmbiguousTypes #-} import Data.Proxy import GHC.TypeLits prefixed [] s = Just s prefixed (p:ps) (s:ss) | p == s = prefixed ps ss prefixed _ _ = Nothing pattern Prefixed :: forall (s :: Symbol). KnownSymbol s => String -> String pattern Prefixed x <- (prefixed (symbolVal (Proxy @s)) -> Just x) secure (Prefixed @"https://" x) = x ++ " is secured" secure _ = "insecure" main :: IO () main = print (secure "https://hi", secure "http://bad")