Skip to content

Instantly share code, notes, and snippets.

@ChrisPenner
Created April 5, 2019 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisPenner/379abb66cfb7b3a554aa61c5b0c49024 to your computer and use it in GitHub Desktop.
Save ChrisPenner/379abb66cfb7b3a554aa61c5b0c49024 to your computer and use it in GitHub Desktop.
Dynamic Programming Comonads using Recursion Schemes
import Data.Functor.Foldable
import Control.Comonad.Cofree as C
import Control.Comonad.Trans.Cofree as CF
cofreeDynExtend :: forall f a b.
Functor f
=> (CofreeF f a (C.Cofree f b) -> b)
-> C.Cofree f a
-> C.Cofree f b
cofreeDynExtend f = cata extract'
where
extract' :: CofreeF f a (C.Cofree f b) -> C.Cofree f b
extract' t@(_ CF.:< bs) = f t C.:< bs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment