@@ -32,6 +32,9 @@ import qualified Reporting.Result as Result
3232
3333
3434
35+-- NITPICK PATTERN MATCHES
36+
37+
3538type Result warning a =
3639 Result.Result () warning Error.Error a
3740
@@ -49,10 +52,6 @@ patternMatches interfaces (Module.Module name _ info) =
4952 <* checkExpression arityDict (Module.program info)
5053
5154
52−
53−-- CHECK EXPRESSIONS
54−
55−
5655checkExpression :: ArityDict -> C.Expr -> Result wrn ()
5756checkExpression arityDict (A.A region expression) =
5857 let
@@ -140,15 +139,32 @@ checkExpression arityDict (A.A region expression) =
140139
141140checkPatterns :: ArityDict -> Region.Region -> Error.Origin -> [Pattern.Canonical] -> Result wrn ()
142141checkPatterns arityDict region origin patterns =
143− let
144− matrix =
145− map (\p -> [fromCanonicalPattern p]) patterns
146− in
147− if isUseful arityDict matrix [Anything] then
148− Result.throw region (Error.Incomplete origin (error "TODO"))
142+ do matrix <- checkRedundant arityDict region [] patterns
143+ if isUseful arityDict matrix [Anything]
144+ then Result.throw region (Error.Incomplete origin (error "TODO"))
145+ else Result.ok ()
146+
147+
148+checkRedundant
149+ :: ArityDict
150+ -> Region.Region
151+ -> [[Pattern]]
152+ -> [Pattern.Canonical]
153+ -> Result wrn [[Pattern]]
154+checkRedundant arityDict region checked unchecked =
155+ case unchecked of
156+ [] ->
157+ Result.ok checked
149158
150− else
151− return ()
159+ nextPattern@(A.A patRegion _) : rest ->
160+ let
161+ next =
162+ [fromCanonicalPattern nextPattern]
163+ in
164+ if isUseful arityDict checked next then
165+ checkRedundant arityDict region (next : checked) rest
166+ else
167+ Result.throw region (Error.Redundant patRegion (length checked + 1))
152168
153169
154170
@@ -163,7 +179,7 @@ checkPatterns arityDict region origin patterns =
163179
164180
165181
166−-- REDUNDANT PATTERNS
182+-- DETECT USEFUL PATTERNS
167183
168184
169185isUseful :: ArityDict -> [[Pattern]] -> [Pattern] -> Bool