@@ -33,10 +33,16 @@ collectAs x = return x
3333-- | Replace _-patterns under @-patterns with fresh names that can be
3434-- used on the RHS
3535replaceUnderscore :: PTerm -> PTerm
36−replaceUnderscore tm = evalState (transformM replaceUnderscore' tm) 0
36+replaceUnderscore tm = evalState (transformM (underAs replaceUnderscore') tm) 0
3737 where
38+ underAs :: (PTerm -> State Int PTerm) -> PTerm -> State Int PTerm
39+ underAs f (PAs fc n tm) = PAs fc n <$> transformM f tm
40+ underAs f x = return x
41+
3842 fresh :: State Int Name
39− fresh = flip sMN "underscorePatVar" <$> get
43+ fresh = modify (+1) >> flip sMN "underscorePatVar" <$> get
44+
45+
4046 replaceUnderscore' :: PTerm -> State Int PTerm
4147 replaceUnderscore' Placeholder = PRef emptyFC <$> fresh
4248 replaceUnderscore' tm = return tm