@@ -151,15 +151,14 @@ underAbstr_ = underAbstr __DUMMY_DOM__
151
151
applyNoBodies :: Definition -> [Arg Term ] -> Definition
152
152
applyNoBodies d args = revert $ d `apply` args
153
153
where
154
- bodies0 :: [( QName , [( Int , Maybe Term )]) ]
155
- bodies0 = everything (++) ( [] `mkQ` go) d
156
- where go ( Defn {defName = q, theDef = Function {funClauses = cls}}) =
157
- [(q, map ( fmap clauseBody) ( zip [ 0 .. ] cls))]
154
+ bodies :: [Maybe Term ]
155
+ bodies = map clauseBody $ funClauses $ theDef d
156
+
157
+ setBody cl b = cl { clauseBody = b }
158
158
159
159
revert :: Definition -> Definition
160
- revert d@ (Defn {defName = q, theDef = f@ (Function {funClauses = cls})})
161
- = d {theDef = f {funClauses = map (\ (i, c) -> c {clauseBody = get i}) (zip [0 .. ] cls)}}
162
- where get i = fromMaybe __IMPOSSIBLE__ $ join $ lookup i <$> lookup q bodies0
160
+ revert d@ (Defn {theDef = f@ (Function {funClauses = cls})}) =
161
+ d {theDef = f {funClauses = zipWith setBody cls bodies}}
163
162
164
163
-- Builtins ---------------------------------------------------------------
165
164
@@ -297,8 +296,6 @@ compilePostulate def = do
297
296
let body = hsError $ " postulate: " ++ pp ty
298
297
return [ Hs. TypeSig () [x] ty
299
298
, Hs. FunBind () [Hs. Match () x [] (Hs. UnGuardedRhs () body) Nothing ] ]
300
- where
301
- Axiom = theDef def
302
299
303
300
type LocalDecls = [(QName , Definition )]
304
301
@@ -338,7 +335,7 @@ compileClause locals qn x c@Clause{clauseTel = tel, namedClausePats = ps', claus
338
335
((show m0 ++ " ._" ) `isPrefixOf` show m) && (q `notElem` localUses)
339
336
splitDecls :: LocalDecls -> ([(Definition , LocalDecls )], LocalDecls )
340
337
splitDecls ds@ ((q,child): rest)
341
- | q `elem` localUses
338
+ | any (( `elem` localUses) . fst ) ds
342
339
, (grandchildren, outer) <- span ((`belongs` q) . fst ) rest
343
340
, (groups, rest') <- splitDecls outer
344
341
= ((child, grandchildren) : groups, rest')
@@ -353,7 +350,8 @@ compileClause locals qn x c@Clause{clauseTel = tel, namedClausePats = ps', claus
353
350
children' = everywhere (mkT (`applyNoBodies` args)) children
354
351
355
352
-- 2. shrink calls to inner modules (unqualify + partially apply module parameters)
356
- shrinkLocalDefs t | Def q es <- t, q `elem` concatMap (\ (d,ds) -> defName d : map fst ds) children
353
+ localNames = concatMap (\ (d,ds) -> defName d : map fst ds) children
354
+ shrinkLocalDefs t | Def q es <- t, q `elem` localNames
357
355
= Def (qualify_ $ qnameName q) (drop argLen es)
358
356
| otherwise = t
359
357
(body', children'') = everywhere (mkT shrinkLocalDefs) (body, children')
0 commit comments