Skip to content

Instantly share code, notes, and snippets.

@evanrelf
Last active May 10, 2024 23:54
Show Gist options
  • Save evanrelf/16d083cd252c877faefc27e106a3f3a2 to your computer and use it in GitHub Desktop.
Save evanrelf/16d083cd252c877faefc27e106a3f3a2 to your computer and use it in GitHub Desktop.
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