Nastya Koroleva
Nastya Koroleva

Reputation: 73

Recursion scheme for tree-like structure

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?

Upvotes: 5

Views: 238

Answers (0)

Related Questions