@@ -140,9 +140,81 @@ checkExpression arityDict (A.A region expression) =
140checkPatterns :: ArityDict -> Region.Region -> Error.Origin -> [Pattern.Canonical] -> Result wrn ()
140checkPatterns :: ArityDict -> Region.Region -> Error.Origin -> [Pattern.Canonical] -> Result wrn ()
141checkPatterns arityDict region origin patterns =
141checkPatterns arityDict region origin patterns =
142 do matrix <- checkRedundant arityDict region [] patterns
142 do matrix <- checkRedundant arityDict region [] patterns
143− if isUseful arityDict matrix [Anything]
143+ case isExhaustive arityDict matrix 1 of
144− then Result.throw region (Error.Incomplete origin (error "TODO"))
148+ Result.throw region (Error.Incomplete origin (map head badPatterns))
152+-- EXHAUSTIVE PATTERNS
155+isExhaustive :: ArityDict -> [[Pattern]] -> Int -> [[Pattern]]
156+isExhaustive arityDict matrix n =
159+ [replicate n Anything]
167+ List.foldl' isCompleteHelp Set.empty matrix
174+ <$> isExhaustive arityDict (Maybe.mapMaybe toDefault matrix) (n - 1)
145− else Result.ok ()
176+ else
178+ (ArityInfo expected info) =
179+ getArityInfo (Set.findMin ctorSet) arityDict
181+ if actual < expected then
183+ <$> Maybe.mapMaybe (isMissing ctorSet) info
184+ <*> isExhaustive arityDict (Maybe.mapMaybe toDefault matrix) (n - 1)
188+ isExhaustiveHelp (name, arity) =
189+ recoverCtor name arity <$>
192+ (Maybe.mapMaybe (specialize name arity) matrix)
195+ concatMap isExhaustiveHelp info
198+isMissing :: Set.Set Var.Canonical -> (Var.Canonical, Int) -> Maybe Pattern
199+isMissing ctorSet (name, arity) =
200+ if Set.member name ctorSet then
204+ Just (Ctor name (replicate arity Anything))
207+recoverCtor :: Var.Canonical -> Int -> [Pattern] -> [Pattern]
208+recoverCtor name arity patterns =
211+ splitAt arity patterns
213+ Ctor name args : rest
217+-- REDUNDANT PATTERNS
148checkRedundant
220checkRedundant
@@ -167,21 +239,6 @@ checkRedundant arityDict region checked unchecked =
167 Result.throw region (Error.Redundant patRegion (length checked + 1))
239 Result.throw region (Error.Redundant patRegion (length checked + 1))
174−--missingPatterns :: [[Pattern]] -> Int -> [Pattern]
175−--missingPatterns matrix n =
182−-- DETECT USEFUL PATTERNS
185isUseful :: ArityDict -> [[Pattern]] -> [Pattern] -> Bool
242isUseful :: ArityDict -> [[Pattern]] -> [Pattern] -> Bool
186isUseful arityDict matrix vector =
243isUseful arityDict matrix vector =
187 case (matrix, vector) of
244 case (matrix, vector) of