Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Haskell

Idiom #94 Print the type of a variable

Print the name of the type of x. Explain if it is a static type or dynamic type.

This may not make sense in all languages.

import Data.Dynamic
print (dynTypeRep (toDyn x))

Haskell is statically typed with type erasure. But all types member of the Typeable type class can be made into dynamic types by toDyn. We print the type rep which prints the name of the dynamic type.
(type x)

New implementation...
< >
programming-idioms.org