mirror of
https://github.com/github/semantic.git
synced 2024-12-29 18:06:14 +03:00
🔥 cata.
This commit is contained in:
parent
07616d5be9
commit
4cbc23b76d
@ -3,15 +3,12 @@ module Data.Term
|
||||
( Term(..)
|
||||
, Syntax(..)
|
||||
, iter
|
||||
, cata
|
||||
, interpret
|
||||
) where
|
||||
|
||||
import Control.Effect.Carrier
|
||||
import Control.Monad (ap)
|
||||
import Control.Monad.Module
|
||||
import Data.Coerce (coerce)
|
||||
import Data.Functor.Const
|
||||
import Data.Scope
|
||||
|
||||
data Term sig a
|
||||
@ -79,15 +76,6 @@ iter var alg bound = go
|
||||
Var a -> var (free a)
|
||||
Term t -> alg (foldSyntax go bound free t)
|
||||
|
||||
cata :: Syntax sig
|
||||
=> (a -> b)
|
||||
-> (forall a . sig (Const b) a -> b)
|
||||
-> (Incr () b -> a)
|
||||
-> (x -> a)
|
||||
-> Term sig x
|
||||
-> b
|
||||
cata var alg k h = getConst . iter (coerce var) (Const . alg) (coerce k) (Const . h)
|
||||
|
||||
|
||||
interpret :: (Carrier sig m, Member eff sig, Syntax eff) => (forall a . Incr () (m a) -> m (Incr () (m a))) -> (a -> m b) -> Term eff a -> m b
|
||||
interpret = iter id send
|
||||
|
Loading…
Reference in New Issue
Block a user