Skip to content

Instantly share code, notes, and snippets.

@nicuveo
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
Save nicuveo/e2ac9256bcf1d85d4cf6134265c00890 to your computer and use it in GitHub Desktop.
{-# 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