@@ -21,8 +21,7 @@ mistakes decls =
21 concat [ infiniteTypeAliases decls
21 concat [ infiniteTypeAliases decls
22 , illFormedTypes decls
22 , illFormedTypes decls
23 , map P.text (duplicateConstructors decls)
23 , map P.text (duplicateConstructors decls)
24− , map P.text (duplicates decls)
24+ , map P.text (duplicates decls) ]
25− , badDerivations decls ]
27dups :: Ord a => [a] -> [a]
26dups :: Ord a => [a] -> [a]
28dups = map head . filter ((>1) . length) . List.group . List.sort
27dups = map head . filter ((>1) . length) . List.group . List.sort
@@ -67,35 +66,14 @@ duplicateConstructors decls =
67 map (dupErr "definition of type constructor") (dups typeCtors) ++
66 map (dupErr "definition of type constructor") (dups typeCtors) ++
68 map (dupErr "definition of data constructor") (dups dataCtors)
67 map (dupErr "definition of data constructor") (dups dataCtors)
70− typeCtors = [ name | D.Datatype name _ _ _ <- decls ]
69+ typeCtors = [ name | D.Datatype name _ _ <- decls ]
71− dataCtors = concat [ map fst patterns | D.Datatype _ _ patterns _ <- decls ]
70+ dataCtors = concat [ map fst patterns | D.Datatype _ _ patterns <- decls ]
73−badDerivations :: [D.Declaration] -> [Doc]
74−badDerivations decls = concatMap badDerivation derivations
77− [ (decl, tvars, derives) | decl@(D.TypeAlias _ tvars _ derives) <- decls ] ++
78− [ (decl, tvars, derives) | decl@(D.Datatype _ tvars _ derives) <- decls ]
80− badDerivation (decl, tvars, derives) =
81− case (tvars, derives) of
83− | D.Json `elem` derives -> [report decl D.Json]
84− | D.Binary `elem` derives -> [report decl D.Binary]
88− P.vcat [ P.text $ "Error: cannot derive '" ++ show derive ++ "' from this type alias."
89− , P.text "Make sure all type variables are replaced with concrete types:"
91− , nest 4 (pretty decl)
94illFormedTypes :: [D.Declaration] -> [Doc]
72illFormedTypes :: [D.Declaration] -> [Doc]
95illFormedTypes decls = map report (Maybe.mapMaybe isIllFormed (aliases ++ adts))
73illFormedTypes decls = map report (Maybe.mapMaybe isIllFormed (aliases ++ adts))
97− aliases = [ (decl, tvars, [tipe]) | decl@(D.TypeAlias _ tvars tipe _) <- decls ]
75+ aliases = [ (decl, tvars, [tipe]) | decl@(D.TypeAlias _ tvars tipe) <- decls ]
98− adts = [ (decl, tvars, concatMap snd ctors) | decl@(D.Datatype _ tvars ctors _) <- decls ]
76+ adts = [ (decl, tvars, concatMap snd ctors) | decl@(D.Datatype _ tvars ctors) <- decls ]
100 freeVars tipe =
78 freeVars tipe =
101 case tipe of
79 case tipe of
@@ -138,8 +116,8 @@ illFormedTypes decls = map report (Maybe.mapMaybe isIllFormed (aliases ++ adts))
139infiniteTypeAliases :: [D.Declaration] -> [Doc]
117infiniteTypeAliases :: [D.Declaration] -> [Doc]
140infiniteTypeAliases decls =
118infiniteTypeAliases decls =
141− [ report name tvars tipe ds | D.TypeAlias name tvars tipe ds <- decls
119+ [ report name tvars tipe | D.TypeAlias name tvars tipe <- decls
142− , infiniteType name tipe ]
120+ , infiniteType name tipe ]
144 infiniteType name tipe =
122 infiniteType name tipe =
145 let infinite = infiniteType name in
123 let infinite = infiniteType name in
@@ -152,11 +130,11 @@ infiniteTypeAliases decls =
152 indented :: D.Declaration -> Doc
130 indented :: D.Declaration -> Doc
153 indented decl = P.text "\n " <> pretty decl <> P.text "\n"
131 indented decl = P.text "\n " <> pretty decl <> P.text "\n"
155− report name args tipe derivations =
133+ report name args tipe =
156 P.vcat [ P.text $ eightyCharLines 0 msg1
134 P.vcat [ P.text $ eightyCharLines 0 msg1
157− , indented $ D.TypeAlias name args tipe derivations
135+ , indented $ D.TypeAlias name args tipe
158 , P.text $ eightyCharLines 0 msg2
136 , P.text $ eightyCharLines 0 msg2
159− , indented $ D.Datatype name args [(name,[tipe])] derivations
137+ , indented $ D.Datatype name args [(name,[tipe])]
160 , P.text $ eightyCharLines 0 msg3 ++ "\n"
138 , P.text $ eightyCharLines 0 msg3 ++ "\n"