Skip to content

Instantly share code, notes, and snippets.

@sdiehl
Created June 18, 2017 18:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdiehl/d033bfdbb02760b23e45ffeca7482957 to your computer and use it in GitHub Desktop.
Save sdiehl/d033bfdbb02760b23e45ffeca7482957 to your computer and use it in GitHub Desktop.
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
module Test where
import GHC.Generics
import Data.Proxy
typeName :: forall a. (Generic a, GTypeName (Rep a)) => Proxy a -> String
typeName Proxy = gtypename (from (undefined :: a))
class GTypeName f where
gtypename :: f a -> String
instance (Datatype c) => GTypeName (M1 i c f) where
gtypename m = datatypeName m
unit :: String
unit = typeName (Proxy :: Proxy ())
int :: String
int = typeName (Proxy :: Proxy Int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment