Skip to content

Generalize copy, perhaps #43

@treeowl

Description

@treeowl

I don't actually know if this "makes sense", but it works for Of and (,), and it kind of smells right.

copy :: (Monad m, Comonad f) => Stream f m r -> Stream f (Stream f m) r
copy = Effect . return . loop where
  loop str = case str of
    Return r -> Return r
    Effect m -> Effect (fmap loop (lift m))
    Step f -> Effect (Step (extend (Return . Step) (fmap loop f)))

Comonad is actually overkill; we only really need Extend from Data.Functor.Extend in semigroupoids. Unfortunately, that's not a superclass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions