
Consider:
-- data T a = T --
Is there anything in the Prelude or a standard library that looks like this? Should there be? What should it be called? 'Singleton'? 'Reified'? 'T'?
I looked but couldn't find anything. Such a simple type constructor is in fact very useful when you need to pass types around to disambiguate class instances. For instance:
-- class HasTypeName t where getTypeName :: T t -> String
instance HasTypeName Int where getTypeName T = "Int"
instance HasTypeName () where getTypeName T = "()"
intName = getTypeName (T :: T Int)
The type T is undoubtedly useful, but I think the example you give isn't a good one. It works perfectly well without the T data type: class HasTypeName t where getTypeName :: t -> String instance HasTypeName Int where getTypeName _ = "Int" instance HasTypeName () where getTypeName _ = "()" intName = getTypeName (undefined :: Int) (this is just like the Typeable class in the Dynamic library, BTW) Cheers, Simon
participants (1)
-
Simon Marlow