@@ -16,6 +16,8 @@
1616
1717module Language.PureScript.Declarations where
1818
19+import Data.Monoid (Monoid(..), mconcat)
20+
1921import Language.PureScript.Types
2022import Language.PureScript.Names
2123import Language.PureScript.Kinds
@@ -562,3 +564,22 @@ everythingOnValues (<>) f g h i j = (f', g', h', i', j')
562564 j' e@(DoNotationBind b v) = j e <> h' b <> g' v
563565 j' e@(DoNotationLet ds) = foldl (<>) (j e) (map f' ds)
564566 j' e@(PositionedDoNotationElement _ e1) = j e <> j' e1
567+
568+accumTypes :: (Monoid r) => (Type -> r) -> (Declaration -> r, Value -> r, Binder -> r, CaseAlternative -> r, DoNotationElement -> r)
569+accumTypes f = everythingOnValues mappend forDecls forValues (const mempty) (const mempty) (const mempty)
570+ where
571+ forDecls (DataDeclaration _ _ dctors) = mconcat (concatMap (map f . snd) dctors)
572+ forDecls (ExternDeclaration _ _ _ ty) = f ty
573+ forDecls (ExternInstanceDeclaration _ cs _ tys) = mconcat (concatMap (map f . snd) cs) `mappend` mconcat (map f tys)
574+ forDecls (TypeClassDeclaration _ _ implies _) = mconcat (concatMap (map f . snd) implies)
575+ forDecls (TypeInstanceDeclaration _ cs _ tys _) = mconcat (concatMap (map f . snd) cs) `mappend` mconcat (map f tys)
576+ forDecls (TypeSynonymDeclaration _ _ ty) = f ty
577+ forDecls (TypeDeclaration _ ty) = f ty
578+ forDecls _ = mempty
579+
580+ forValues (TypeClassDictionary _ (_, cs) _) = mconcat (map f cs)
581+ forValues (SuperClassDictionary _ tys) = mconcat (map f tys)
582+ forValues (TypedValue _ _ ty) = f ty
583+ forValues _ = mempty
584+
585+