Subject: QuickCheck Fun with Phantom Types Newsgroups: gmane.comp.lang.haskell.cafe Date: Saturday 13th May 2006 12:49:53 UTC (over 12 years ago) 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) |
|||