Consider the following :
module Main where
data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show, Read, Eq)
data Container a b = Container{contField :: b a} deriving (Show)
result = Container {contField = Node 'a' EmptyTree EmptyTree}
main = do
print result
If I load this into ghci, then I get the following for the type of result
:
*Main> :t result
result :: Container Char Tree
How can I print the type Container Char Tree
from within the program? I was trying to adapt the solution given at Haskell — get TypeRep from concrete type instance but I got stuck because I could not find a way to use typeOf
in conjunction with type constructors of kind * -> *
[EDIT] : Some of the methods in this post have been deprecated in ghc 7.8.1 Release notes for version 7.8.1 :
Typeable is now poly-kinded, making Typeable1, Typeable2, etc., obsolete, deprecated, and relegated to Data.OldTypeable. Furthermore, user-written instances of Typeable are now disallowed: use deriving or the new extension -XAutoDeriveTypeable, which will create Typeable instances for every datatype declared in the module.