
I was doing Exercise 5 of Ralf's Fun with Phantom Types and naturally thought I'd check my solution with QuickCheck. The best I could was this. Is there something better? Can you somehow generate random types as well as random values in those types? Thanks, Dominic. PS the full source for my solution with tests is attached. prop_Idem t x = x == uncompress t (compress t x) instance Arbitrary Char where arbitrary = oneof (map return ['A'..'z']) class Reflect a where reflect :: Type a instance Reflect Int where reflect = RInt instance Reflect Char where reflect = RChar instance (Reflect a, Reflect b) => Reflect (a,b) where reflect = RPair reflect reflect instance Reflect a => Reflect [a] where reflect = RList reflect type Test1 = Int -> Bool type Test2 = (Int,Int) -> Bool type Test3 = String -> Bool type Test4 = (String,String) -> Bool main = do quickCheck ((prop_Idem reflect) :: Test1) quickCheck ((prop_Idem reflect) :: Test2) quickCheck ((prop_Idem reflect) :: Test3) quickCheck ((prop_Idem reflect) :: Test4)

Since Don was kind enough to include my question in HWN (http://www.cse.unsw.edu.au/~dons/code/hwn/archives/20060522.html) and I have now come up with a solution, I have created a wiki page (http://haskell.org/haskellwiki/QuickCheck_/_GADT) with it in. Dominic.
participants (1)
-
Dominic Steinitz