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

Commit d1c6d9f

Browse files
committed
Define a catamorphism over Terms.
1 parent 4306112 commit d1c6d9f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

semantic-core/src/Data/Term.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ module Data.Term
33
( Term(..)
44
, Syntax(..)
55
, iter
6+
, cata
67
) where
78

89
import Control.Effect.Carrier
910
import Control.Monad (ap)
1011
import Control.Monad.Module
12+
import Data.Coerce (coerce)
13+
import Data.Functor.Const
1114
import Data.Scope
1215

1316
data Term sig a
@@ -74,3 +77,12 @@ iter var alg bound = go
7477
go free = \case
7578
Var a -> var (free a)
7679
Term t -> alg (foldSyntax go bound free t)
80+
81+
cata :: Syntax sig
82+
=> (a -> b)
83+
-> (forall a . sig (Const b) a -> b)
84+
-> (Incr () b -> a)
85+
-> (x -> a)
86+
-> Term sig x
87+
-> b
88+
cata var alg k h = getConst . iter (coerce var) (Const . alg) (coerce k) (Const . h)

0 commit comments

Comments
 (0)