Recursion scheme for tree-like structure

230 views Asked by At

I'm trying to build the following recursion scheme:

{-# LANGUAGE DeriveFunctor #-}
import Data.Functor.Foldable
import Control.Comonad
import Control.Comonad.Cofree

data Term a = Str String | Array [a] deriving (Show, Functor)
type Tree = Fix Term
type Annotated = Cofree Term String
-- i.e. Annotated = String × Term Annotated

something :: (Term String -> String) -> Tree -> Annotated
something algebra = cata algebra' where
    algebra' t = algebra (extract <$> t) :< t

How can I compose this something in the most generic and minimalistic way, using stock functions from modern recursion scheme libraries such as recursion-schemes? Is there a well-known name for this scheme?

0

There are 0 answers