Skip to content

Instantly share code, notes, and snippets.

Created December 26, 2020 22:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
import Data.Proxy
import Data.Typeable
contains :: forall a b. (Typeable a, Typeable b) => Bool
contains = go typeB
where typeA = typeRep (Proxy :: Proxy a)
typeB = typeRep (Proxy :: Proxy b)
go x = x == typeA || any go (typeRepArgs x)
main :: IO ()
main = do
print $ contains @Int @(Either (Maybe [IO Int]) String)
print $ contains @[IO Int] @(Either (Maybe [IO Int]) String)
print $ contains @(Maybe Int) @(Either (Maybe [IO Int]) String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment