Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit ff22c0b

Browse files
committed
General fold over Terms.
1 parent 6812e35 commit ff22c0b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

semantic-analysis/src/Analysis/Syntax.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Analysis.Syntax
33
( -- * Syntax
44
Term(..)
55
, subterms
6+
, foldTerm
67
) where
78

89
import qualified Data.Set as Set
@@ -30,3 +31,9 @@ subterms :: (forall t . Eq t => Eq (sig t), forall t . Ord t => Ord (sig t), Ord
3031
subterms t = case t of
3132
Var _ -> Set.singleton t
3233
Term s -> Set.insert t (foldMap subterms s)
34+
35+
foldTerm :: Functor sig => (v -> r) -> (sig r -> r) -> (Term sig v -> r)
36+
foldTerm var sig = go
37+
where
38+
go (Var v) = var v
39+
go (Term s) = sig (go <$> s)

0 commit comments

Comments
 (0)