@@ -32,20 +32,21 @@ getLets decls = defs : concatMap getSubLets defs
3232 Def pattern expr -> [ defs | Let defs _ <- universeBi expr ]
3333 TypeAnnotation _ _ -> []
3434
35−msg :: String
36−msg = "Syntax Error: There can only be one "
37−
3835dups :: Eq a => [a] -> [a]
3936dups = map head . filter ((>1) . length) . List.group
4037
38+dupErr :: String -> String -> String
39+dupErr err x =
40+ "Syntax Error: There can only be one " ++ err ++ " '" ++ x ++ "'."
41+
4142duplicates :: [Def t v] -> [String]
4243duplicates defs =
4344 map defMsg (dups definitions) ++ map annMsg (dups annotations)
4445 where
4546 annotations = List.sort [ name | TypeAnnotation name _ <- defs ]
4647 definitions = List.sort $ concatMap Set.toList [ boundVars pattern | Def pattern _ <- defs ]
47− defMsg x = msg ++ "definition of '" ++ x ++ "'."
48− annMsg x = msg ++ "type annotation for '" ++ x ++ "'."
48+ defMsg = dupErr "definition of"
49+ annMsg = dupErr "type annotation for"
4950
5051duplicateConstructors :: [Declaration t v] -> [String]
5152duplicateConstructors decls =
@@ -54,8 +55,8 @@ duplicateConstructors decls =
5455 typeCtors = List.sort [ name | Datatype name _ _ <- decls ]
5556 dataCtors = List.sort . concat $
5657 [ map fst patterns | Datatype _ _ patterns <- decls ]
57− dataMsg x = msg ++ "definition of data constructor '" ++ x ++ "'."
58− typeMsg x = msg ++ "definition of type constructor '" ++ x ++ "'."
58+ dataMsg = dupErr "definition of data constructor"
59+ typeMsg = dupErr "definition of type constructor"
5960
6061badOrder :: [Def t v] -> [String]
6162badOrder defs = go defs