Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize copy, perhaps #43

Open
treeowl opened this issue Sep 8, 2017 · 7 comments
Open

Generalize copy, perhaps #43

treeowl opened this issue Sep 8, 2017 · 7 comments

Comments

@treeowl
Copy link

treeowl commented Sep 8, 2017

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.

@treeowl
Copy link
Author

treeowl commented Sep 8, 2017

I was talking with Cale Gibbard, who said it seemed to go with an extract-like generalization of effects, which is very definitely possible as well, forming some sort of higher-level comonad or something:

effects :: (Monad m, Comonad f) => Stream f m r -> m r

@ocharles
Copy link

ocharles commented Sep 8, 2017

If you only need extend you could also ask that to be passed in as a parameter. Not sure if that permits other "interesting" extends

@treeowl
Copy link
Author

treeowl commented Sep 8, 2017

@ocharles, that's a good idea for avoiding the dependency. It's kind of an ugly parameter, and would require a separate function (rather than replacing copy), but that seems fairly tolerable.

@ocharles
Copy link

ocharles commented Sep 8, 2017

Well, I suggest it more from wondering if as you only want Extend you really do just want to supply that function. Plus, maybe it means something interesting (like traverse being useful when given as a parameter as it's a traversal)

@treeowl
Copy link
Author

treeowl commented Sep 8, 2017

@ocharles, yes, that's a good point too, and the answer is ... yes! We can get

copygen :: (Monad m, Functor f)
        => (forall a b. (f a -> b) -> f a -> g b)
        -> Stream f m r -> Stream f (Stream g m) r

@treeowl
Copy link
Author

treeowl commented Sep 8, 2017

Actually, we can even get

copygen :: (Monad m, Functor g)
        => (forall a b. (f a -> b) -> g a -> h b)
        -> Stream g m r -> Stream f (Stream h m) r

@andrewthad
Copy link
Contributor

This is no longer the official repo for streaming. Please continue discussion of this issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants