Last active
May 10, 2024 23:54
-
-
Save evanrelf/16d083cd252c877faefc27e106a3f3a2 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
module Main (main) where | |
import Control.Monad (when) | |
import Data.Proxy (Proxy (..)) | |
import Data.String (IsString (..)) | |
import Data.Void (Void) | |
import Type.Reflection | |
typeName | |
:: forall a s proxy | |
. (Typeable a, IsString s) | |
=> proxy a -> s | |
typeName _ = | |
fromString . tyConName . typeRepTyCon $ TypeRep @a | |
main :: IO () | |
main = do | |
let typeNames = | |
[ (typeName (Proxy @()), "()") | |
, (typeName (Proxy @Void), "Void") | |
, (typeName (Proxy @Bool), "Bool") | |
, (typeName (Proxy @(Proxy ())), "Proxy") | |
, (typeName (Proxy @(Maybe ())), "Maybe") | |
] | |
print typeNames | |
let itWorks = and $ do | |
(actual, expected) <- typeNames | |
pure $ expected == actual | |
when itWorks $ putStrLn "It works!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment