Created
December 26, 2020 22:00
-
-
Save nicuveo/e2ac9256bcf1d85d4cf6134265c00890 to your computer and use it in GitHub Desktop.
This file contains 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 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