# Singular Type Constructor

**Simon Marlow
**
[email protected]

*Tue, 31 Jul 2001 09:55:47 +0100*

>* Consider:
*>*=20
*>* --
*>* data T a =3D T
*>* --
*>*=20
*>* Is there anything in the Prelude or a standard library that=20
*>* looks like=20
*>* this? Should there be? What should it be called? 'Singleton'?=20
*>* 'Reified'?=20
*>* 'T'?
*>*=20
*>* I looked but couldn't find anything. Such a simple type=20
*>* constructor is in=20
*>* fact very useful when you need to pass types around to=20
*>* disambiguate class=20
*>* instances. For instance:
*>*=20
*>* --
*>* class HasTypeName t where
*>* getTypeName :: T t -> String
*>* =09
*>* instance HasTypeName Int where
*>* getTypeName T =3D "Int"
*>* =09
*>* instance HasTypeName () where
*>* getTypeName T =3D "()"
*>*=20
*>* intName =3D 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
=09
instance HasTypeName Int where
getTypeName _ =3D "Int"
=09
instance HasTypeName () where
getTypeName _ =3D "()"
=20
intName =3D getTypeName (undefined :: Int)
(this is just like the Typeable class in the Dynamic library, BTW)
Cheers,
Simon