1{-# LANGUAGE CPP #-} 2{-# OPTIONS -fglasgow-exts #-} 3 4-- These are simple tests to observe (data)type representations. 5module Datatype where 6 7import Test.HUnit 8 9import Data.Tree 10import Data.Generics 11 12-- A simple polymorphic datatype 13data MyDataType a = MyDataType a 14 deriving (Typeable, Data) 15 16 17-- Some terms and corresponding type representations 18myTerm = undefined :: MyDataType Int 19myTypeRep = typeOf myTerm -- type representation in Typeable 20myDataType = dataTypeOf myTerm -- datatype representation in Data 21 22#if MIN_VERSION_base(4,5,0) 23myTyCon = typeRepTyCon myTypeRep -- type constructor via Typeable 24myString1 = tyConName myTyCon -- type constructor via Typeable 25myString2 = dataTypeName myDataType -- type constructor via Data 26 27-- Main function for testing 28tests = show ( myTypeRep 29 , ( myDataType 30 , ( tyconModule myString1 31 , ( tyconUQname myString1 32 , ( tyconModule myString2 33 , ( tyconUQname myString2 34 )))))) 35 ~?= output 36 37#if __GLASGOW_HASKELL__ >= 709 38-- In GHC 7.10 module name is stripped from DataType 39output = "(MyDataType Int,(DataType {tycon = \"MyDataType\", datarep = AlgRep [MyDataType]},(\"\",(\"MyDataType\",(\"\",\"MyDataType\")))))" 40#else 41output = "(MyDataType Int,(DataType {tycon = \"Datatype.MyDataType\", datarep = AlgRep [MyDataType]},(\"\",(\"MyDataType\",(\"Datatype\",\"MyDataType\")))))" 42#endif 43 44#else 45 46tests = show ( myTypeRep, myDataType ) 47 ~?= output 48 49#if __GLASGOW_HASKELL__ >= 701 50output = "(MyDataType Int,DataType {tycon = \"Datatype.MyDataType\", datarep = AlgRep [MyDataType]})" 51#else 52output = "(Datatype.MyDataType Int,DataType {tycon = \"Datatype.MyDataType\", datarep = AlgRep [MyDataType]})" 53#endif 54 55#endif 56