Skip to content

Commit f359821

Browse files
committed
Lint: merge: refactor go
1 parent 4c3f421 commit f359821

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/Nix/Lint.hs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,19 @@ merge context = go
170170
-> m [NTypeF m (Symbolic m)]
171171
go [] _ = stub
172172
go _ [] = stub
173-
go (x : xs) (y : ys) = case (x, y) of
174-
(TStr , TStr ) -> (TStr :) <$> go xs ys
175-
(TPath, TPath) -> (TPath :) <$> go xs ys
173+
go xxs@(x : xs) yys@(y : ys) = case (x, y) of
174+
(TStr , TStr ) -> (TStr :) <$> rest
175+
(TPath, TPath) -> (TPath :) <$> rest
176176
(TConstant ls, TConstant rs) ->
177-
(TConstant (ls `intersect` rs) :) <$> go xs ys
177+
(TConstant (ls `intersect` rs) :) <$> rest
178178
(TList l, TList r) ->
179-
(\l' ->
180-
(\r' -> do
181-
m <- defer $ unify context l' r'
182-
(TList m :) <$> go xs ys
183-
) =<< demand r
184-
) =<< demand l
185-
(TSet x , TSet Nothing ) -> (TSet x :) <$> go xs ys
186-
(TSet Nothing , TSet x ) -> (TSet x :) <$> go xs ys
179+
do
180+
l' <- demand l
181+
r' <- demand r
182+
m <- defer $ unify context l' r'
183+
(TList m :) <$> rest
184+
(TSet x , TSet Nothing ) -> (TSet x :) <$> rest
185+
(TSet Nothing , TSet x ) -> (TSet x :) <$> rest
187186
(TSet (Just l), TSet (Just r)) -> do
188187
m <- sequenceA $ M.intersectionWith
189188
(\ i j ->
@@ -198,15 +197,18 @@ merge context = go
198197
id
199198
((TSet (pure m) :) <$>)
200199
(not $ M.null m)
201-
(go xs ys)
200+
rest
202201

203202
(TClosure{}, TClosure{}) ->
204203
throwError $ ErrorCall "Cannot unify functions"
205204
(TBuiltin _ _, TBuiltin _ _) ->
206205
throwError $ ErrorCall "Cannot unify builtin functions"
207-
_ | compareTypes x y == LT -> go xs (y : ys)
208-
| compareTypes x y == GT -> go (x : xs) ys
206+
_ | compareTypes x y == LT -> go xs yys
207+
| compareTypes x y == GT -> go xxs ys
209208
| otherwise -> error "impossible"
209+
where
210+
rest :: m [NTypeF m (Symbolic m)]
211+
rest = go xs ys
210212

211213
{-
212214
mergeFunctions pl nl fl pr fr xs ys = do

0 commit comments

Comments
 (0)