@@ -493,50 +493,56 @@ everywhereWithContextOnValuesM s0 f g h i j = (f'' s0, g'' s0, h'' s0, i'' s0, j
493493 k' s (ConditionGuard e) = ConditionGuard <$> g'' s e
494494 k' s (PatternGuard b e) = PatternGuard <$> h'' s b <*> g'' s e
495495
496- data ScopedIdent = LocalIdent Ident | ToplevelIdent Ident
496+ data ScopedName = LocalName Name | ToplevelName Name
497497 deriving (Show , Eq , Ord )
498498
499- inScope :: Ident -> S. Set ScopedIdent -> Bool
500- inScope i s = (LocalIdent i `S.member` s) || (ToplevelIdent i `S.member` s)
499+ inScope' :: (a -> Name ) -> a -> S. Set ScopedName -> Bool
500+ inScope' ctor i s = (LocalName (ctor i) `S.member` s) || (ToplevelName (ctor i) `S.member` s)
501+
502+ inScope :: Ident -> S. Set ScopedName -> Bool
503+ inScope = inScope' IdentName
504+
505+ typeInScope :: ProperName 'TypeName -> S. Set ScopedName -> Bool
506+ typeInScope = inScope' TyName
501507
502508everythingWithScope
503509 :: forall r
504510 . (Monoid r )
505- => (S. Set ScopedIdent -> Declaration -> r )
506- -> (S. Set ScopedIdent -> Expr -> r )
507- -> (S. Set ScopedIdent -> Binder -> r )
508- -> (S. Set ScopedIdent -> CaseAlternative -> r )
509- -> (S. Set ScopedIdent -> DoNotationElement -> r )
510- -> ( S. Set ScopedIdent -> Declaration -> r
511- , S. Set ScopedIdent -> Expr -> r
512- , S. Set ScopedIdent -> Binder -> r
513- , S. Set ScopedIdent -> CaseAlternative -> r
514- , S. Set ScopedIdent -> DoNotationElement -> r
511+ => (S. Set ScopedName -> Declaration -> r )
512+ -> (S. Set ScopedName -> Expr -> r )
513+ -> (S. Set ScopedName -> Binder -> r )
514+ -> (S. Set ScopedName -> CaseAlternative -> r )
515+ -> (S. Set ScopedName -> DoNotationElement -> r )
516+ -> ( S. Set ScopedName -> Declaration -> r
517+ , S. Set ScopedName -> Expr -> r
518+ , S. Set ScopedName -> Binder -> r
519+ , S. Set ScopedName -> CaseAlternative -> r
520+ , S. Set ScopedName -> DoNotationElement -> r
515521 )
516522everythingWithScope f g h i j = (f'', g'', h'', i'', \ s -> snd . j'' s)
517523 where
518- f'' :: S. Set ScopedIdent -> Declaration -> r
524+ f'' :: S. Set ScopedName -> Declaration -> r
519525 f'' s a = f s a <> f' s a
520526
521- f' :: S. Set ScopedIdent -> Declaration -> r
527+ f' :: S. Set ScopedName -> Declaration -> r
522528 f' s (DataBindingGroupDeclaration ds) =
523- let s' = S. union s (S. fromList (map ToplevelIdent (mapMaybe getDeclIdent (NEL. toList ds))))
529+ let s' = S. union s (S. fromList (map ToplevelName (mapMaybe declName (NEL. toList ds))))
524530 in foldMap (f'' s') ds
525531 f' s (ValueDecl _ name _ bs val) =
526- let s' = S. insert (ToplevelIdent name) s
532+ let s' = S. insert (ToplevelName ( IdentName name) ) s
527533 s'' = S. union s' (S. fromList (concatMap localBinderNames bs))
528534 in foldMap (h'' s') bs <> foldMap (l' s'') val
529535 f' s (BindingGroupDeclaration ds) =
530- let s' = S. union s (S. fromList (NEL. toList (fmap (\ ((_, name), _, _) -> ToplevelIdent name) ds)))
536+ let s' = S. union s (S. fromList (NEL. toList (fmap (\ ((_, name), _, _) -> ToplevelName ( IdentName name) ) ds)))
531537 in foldMap (\ (_, _, val) -> g'' s' val) ds
532538 f' s (TypeClassDeclaration _ _ _ _ _ ds) = foldMap (f'' s) ds
533539 f' s (TypeInstanceDeclaration _ _ _ _ _ _ _ (ExplicitInstance ds)) = foldMap (f'' s) ds
534540 f' _ _ = mempty
535541
536- g'' :: S. Set ScopedIdent -> Expr -> r
542+ g'' :: S. Set ScopedName -> Expr -> r
537543 g'' s a = g s a <> g' s a
538544
539- g' :: S. Set ScopedIdent -> Expr -> r
545+ g' :: S. Set ScopedName -> Expr -> r
540546 g' s (Literal _ l) = lit g'' s l
541547 g' s (UnaryMinus _ v1) = g'' s v1
542548 g' s (BinaryNoParens op v1 v2) = g'' s op <> g'' s v1 <> g'' s v2
@@ -553,7 +559,7 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
553559 g' s (Case vs alts) = foldMap (g'' s) vs <> foldMap (i'' s) alts
554560 g' s (TypedValue _ v1 _) = g'' s v1
555561 g' s (Let _ ds v1) =
556- let s' = S. union s (S. fromList (map LocalIdent (mapMaybe getDeclIdent ds)))
562+ let s' = S. union s (S. fromList (map LocalName (mapMaybe declName ds)))
557563 in foldMap (f'' s') ds <> g'' s' v1
558564 g' s (Do _ es) = fold . snd . mapAccumL j'' s $ es
559565 g' s (Ado _ es v1) =
@@ -562,46 +568,46 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
562568 g' s (PositionedValue _ _ v1) = g'' s v1
563569 g' _ _ = mempty
564570
565- h'' :: S. Set ScopedIdent -> Binder -> r
571+ h'' :: S. Set ScopedName -> Binder -> r
566572 h'' s a = h s a <> h' s a
567573
568- h' :: S. Set ScopedIdent -> Binder -> r
574+ h' :: S. Set ScopedName -> Binder -> r
569575 h' s (LiteralBinder _ l) = lit h'' s l
570576 h' s (ConstructorBinder _ _ bs) = foldMap (h'' s) bs
571577 h' s (BinaryNoParensBinder b1 b2 b3) = foldMap (h'' s) [b1, b2, b3]
572578 h' s (ParensInBinder b) = h'' s b
573- h' s (NamedBinder _ name b1) = h'' (S. insert (LocalIdent name) s) b1
579+ h' s (NamedBinder _ name b1) = h'' (S. insert (LocalName ( IdentName name) ) s) b1
574580 h' s (PositionedBinder _ _ b1) = h'' s b1
575581 h' s (TypedBinder _ b1) = h'' s b1
576582 h' _ _ = mempty
577583
578- lit :: (S. Set ScopedIdent -> a -> r ) -> S. Set ScopedIdent -> Literal a -> r
584+ lit :: (S. Set ScopedName -> a -> r ) -> S. Set ScopedName -> Literal a -> r
579585 lit go s (ArrayLiteral as) = foldMap (go s) as
580586 lit go s (ObjectLiteral as) = foldMap (go s . snd ) as
581587 lit _ _ _ = mempty
582588
583- i'' :: S. Set ScopedIdent -> CaseAlternative -> r
589+ i'' :: S. Set ScopedName -> CaseAlternative -> r
584590 i'' s a = i s a <> i' s a
585591
586- i' :: S. Set ScopedIdent -> CaseAlternative -> r
592+ i' :: S. Set ScopedName -> CaseAlternative -> r
587593 i' s (CaseAlternative bs gs) =
588594 let s' = S. union s (S. fromList (concatMap localBinderNames bs))
589595 in foldMap (h'' s) bs <> foldMap (l' s') gs
590596
591- j'' :: S. Set ScopedIdent -> DoNotationElement -> (S. Set ScopedIdent , r )
597+ j'' :: S. Set ScopedName -> DoNotationElement -> (S. Set ScopedName , r )
592598 j'' s a = let (s', r) = j' s a in (s', j s a <> r)
593599
594- j' :: S. Set ScopedIdent -> DoNotationElement -> (S. Set ScopedIdent , r )
600+ j' :: S. Set ScopedName -> DoNotationElement -> (S. Set ScopedName , r )
595601 j' s (DoNotationValue v) = (s, g'' s v)
596602 j' s (DoNotationBind b v) =
597603 let s' = S. union (S. fromList (localBinderNames b)) s
598604 in (s', h'' s b <> g'' s v)
599605 j' s (DoNotationLet ds) =
600- let s' = S. union s (S. fromList (map LocalIdent (mapMaybe getDeclIdent ds)))
606+ let s' = S. union s (S. fromList (map LocalName (mapMaybe declName ds)))
601607 in (s', foldMap (f'' s') ds)
602608 j' s (PositionedDoNotationElement _ _ e1) = j'' s e1
603609
604- k' :: S. Set ScopedIdent -> Guard -> (S. Set ScopedIdent , r )
610+ k' :: S. Set ScopedName -> Guard -> (S. Set ScopedName , r )
605611 k' s (ConditionGuard e) = (s, g'' s e)
606612 k' s (PatternGuard b e) =
607613 let s' = S. union (S. fromList (localBinderNames b)) s
@@ -612,12 +618,7 @@ everythingWithScope f g h i j = (f'', g'', h'', i'', \s -> snd . j'' s)
612618 let (s', r) = k' s grd
613619 in r <> l' s' (GuardedExpr gs e)
614620
615- getDeclIdent :: Declaration -> Maybe Ident
616- getDeclIdent (ValueDeclaration vd) = Just (valdeclIdent vd)
617- getDeclIdent (TypeDeclaration td) = Just (tydeclIdent td)
618- getDeclIdent _ = Nothing
619-
620- localBinderNames = map LocalIdent . binderNames
621+ localBinderNames = map (LocalName . IdentName ) . binderNames
621622
622623accumTypes
623624 :: (Monoid r )
0 commit comments