@@ -120,26 +120,6 @@ genClauses fc n xs given
120120 as' <- mkArg as
121121 return (a':as')
122122
123−fnub xs = fnub' [] xs
124−
125−fnub' acc (x : xs) | x `qelem` acc = fnub' acc (filter (not.(quickEq x)) xs)
126− | otherwise = fnub' (x : acc) xs
127−fnub' acc [] = acc
128−
129−-- quick check for constructor equality
130−quickEq :: PTerm -> PTerm -> Bool
131−quickEq (PConstant n) (PConstant n') = n == n'
132−quickEq (PRef _ n) (PRef _ n') = n == n'
133−quickEq (PApp _ t as) (PApp _ t' as')
134− | length as == length as'
135− = quickEq t t' && and (zipWith quickEq (map getTm as) (map getTm as'))
136−quickEq Placeholder Placeholder = True
137−quickEq x y = False
138−
139−qelem x [] = False
140−qelem x (y : ys) | x `quickEq` y = True
141− | otherwise = qelem x ys
142−
143123-- FIXME: Just look for which one is the deepest, then generate all
144124-- possibilities up to that depth.
145125
@@ -244,6 +224,31 @@ genAll i args
244224 -> PApp fc (PRef fc x) (map (upd Placeholder) pargs)
245225 _ -> error "Can't happen - genAll"
246226
227+ fnub :: [PTerm] -> [PTerm]
228+ fnub xs = fnub' [] xs
229+
230+ fnub' :: [PTerm] -> [PTerm] -> [PTerm]
231+ fnub' acc (x : xs) | x `qelem` acc = fnub' acc (filter (not.(quickEq x)) xs)
232+ | otherwise = fnub' (x : acc) xs
233+ fnub' acc [] = acc
234+
235+ -- quick check for constructor equality
236+ quickEq :: PTerm -> PTerm -> Bool
237+ quickEq (PConstant n) (PConstant n') = n == n'
238+ quickEq (PRef _ n) (PRef _ n') = n == n'
239+ quickEq (PApp _ t as) (PApp _ t' as')
240+ | length as == length as'
241+ = quickEq t t' && and (zipWith quickEq (map getTm as) (map getTm as'))
242+ quickEq Placeholder Placeholder = True
243+ quickEq x y = False
244+
245+ qelem :: PTerm -> [PTerm] -> Bool
246+ qelem x [] = False
247+ qelem x (y : ys) | x `quickEq` y = True
248+ | otherwise = qelem x ys
249+
250+
251+upd :: t -> PArg' t -> PArg' t
247252upd p' p = p { getTm = p' }
248253
249254-- Check whether function and all descendants cover all cases (partial is
@@ -706,8 +711,10 @@ checkMP ist i mp = if i > 0
706711 | [Partial _] <- lookupTotal f (tt_ctxt ist) = Partial (Other [f])
707712 | otherwise = Unchecked
708713
714+allNothing :: [Maybe a] -> Bool
709715allNothing xs = null (collapseNothing (zip xs [0..]))
710716
717+collapseNothing :: [(Maybe a, b)] -> [(Maybe a, b)]
711718collapseNothing ((Nothing, _) : xs)
712719 = filter (\ (x, _) -> case x of
713720 Nothing -> False
@@ -715,10 +722,12 @@ collapseNothing ((Nothing, _) : xs)
715722collapseNothing (x : xs) = x : collapseNothing xs
716723collapseNothing [] = []
717724
725+noPartial :: [Totality] -> Totality
718726noPartial (Partial p : xs) = Partial p
719727noPartial (_ : xs) = noPartial xs
720728noPartial [] = Total []
721729
730+collapse :: [Totality] -> Totality
722731collapse xs = collapse' Unchecked xs
723732collapse' def (Total r : xs) = Total r
724733collapse' def (Unchecked : xs) = collapse' def xs