5

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?

  • Welcome to Stack Overflow! Looks to me like you might be able to implement `something` using [`hoist`](https://hackage.haskell.org/package/recursion-schemes-5.1.3/docs/Data-Functor-Foldable.html#v:hoist). – Benjamin Hodgson Jun 16 '20 at 20:51
  • On second thoughts, i think that won't work because `hoist`'s rank-2 type doesn't give you access to the base functor's arg. – Benjamin Hodgson Jun 16 '20 at 21:01
  • 4
    Potential close voters: the scope of this question is perfectly fine; it doesn't "need more focus". It doesn't matter at all that the post happens to have two question marks in it. – duplode Jun 17 '20 at 01:03

0 Answers0