@@ -54,33 +54,38 @@ instance Arbitrary Pattern where
54 PLiteral l -> PLiteral <$> shrink l
54 PLiteral l -> PLiteral <$> shrink l
55 PAlias s p -> p : (PAlias <$> shrinkWHead s <*> shrink p)
55 PAlias s p -> p : (PAlias <$> shrinkWHead s <*> shrink p)
56 PData s ps -> ps ++ (PData <$> shrinkWHead s <*> shrink ps)
56 PData s ps -> ps ++ (PData <$> shrinkWHead s <*> shrink ps)
57− where shrinkWHead (x:xs) = (x:) <$> shrink xs
59−isValidType :: Type -> Bool
58+shrinkWHead :: Arbitrary a => [a] -> [[a]]
60−isValidType (Lambda s t) = isValidType s && isValidType t
59+shrinkWHead [] = error "Should be nonempty"
61−isValidType (Record [] (Just _)) = False
60+shrinkWHead (x:xs) = (x:) <$> shrink xs
62−isValidType (Record (("",_):_) _) = False
63−isValidType (Record fs _) = all isValidType $ map snd fs
64−isValidType (Data _ []) = False
65−isValidType (Data _ ts) = all isValidType ts
68instance Arbitrary Type where
62instance Arbitrary Type where
69− arbitrary = sized tipe `suchThat` isValidType
63+ arbitrary = sized tipe
70 where tipe :: Int -> Gen Type
64 where tipe :: Int -> Gen Type
71 tipe n = oneof [ Lambda <$> depthTipe <*> depthTipe
65 tipe n = oneof [ Lambda <$> depthTipe <*> depthTipe
72 , Var <$> lowVar
66 , Var <$> lowVar
73− , Data <$> capVar <*> listOf1 depthTipe
67+ , Data <$> capVar <*> listOf depthTipe
74− , Record <$> listOf ((,) <$> lowVar <*> depthTipe) <*> maybeOf lowVar
68+ , Record <$> listOf1 field <*> (Just <$> lowVar)
69+ , Record <$> listOf field <*> pure Nothing
76 where depthTipe :: Gen Type
71 where depthTipe :: Gen Type
77− depthTipe = choose (0,n) >>= tipe
72+ depthTipe = do
75+ field :: Gen (String, Type)
76+ field = (,) <$> lowVar <*> depthTipe
79− shrink tipe = filter isValidType $ case tipe of
78+ shrink tipe = case tipe of
80 Lambda s t -> Lambda <$> shrink s <*> shrink t
79 Lambda s t -> Lambda <$> shrink s <*> shrink t
81 Var _ -> []
80 Var _ -> []
82− Data n ts -> Data n <$> shrink ts
81+ Data n ts -> Data <$> shrinkWHead n <*> shrink ts
83− Record fs t -> Record <$> shrink fs <*> pure t
82+ Record fs t -> case t of
83+ Nothing -> Record <$> shrinkList shrinkField fs <*> pure Nothing
86+ fields <- filter (not . null) $ shrinkList shrinkField fs
87+ return $ Record fields t
88+ where shrinkField (n,t) = (,) <$> shrinkWHead n <*> shrink t
85lowVar :: Gen String
90lowVar :: Gen String
86lowVar = notReserved $ (:) <$> lower <*> listOf varLetter
91lowVar = notReserved $ (:) <$> lower <*> listOf varLetter