Skip to content

Conversation

@Ericson2314
Copy link
Contributor

@Ericson2314 Ericson2314 commented Jun 26, 2019

We now have:

    Sink     Source
    /   \    /   \
   /     \  /     \
Writer   State    Reader

HasStream has been renamed (with deprecated aliases for compat) to HasSink, to
illustrate the symmetry.

WIP because I need to review myself, and probably also fix examples.

Fixes #63.

Copy link
Member

@aspiwack aspiwack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I browsed this quickly. I rather like the idea of Sink and Source.

Thanks for this. And let us know when this is ready for careful review.

@Ericson2314 Ericson2314 force-pushed the stream-reader branch 4 times, most recently from 88a8d3c to 9cde9c1 Compare June 26, 2019 19:59
@Ericson2314 Ericson2314 changed the title WIP: Introduce HasSource, and make superclasses Introduce HasSource, and make superclasses Jun 26, 2019
@Ericson2314
Copy link
Contributor Author

Have at it!

Copy link
Member

@aherrmann aherrmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this PR, thank you! Just a few small comments, then I'm happy to merge it.

CountLog
Error
Reader
Sink
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you happen to have a Source only example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should make one.

StateOverStream (StateT Int (Stream (Of (Int, Char)) IO) a)
deriving (Functor, Applicative, Monad)
deriving (HasState "counter" Int) via
deriving (HasSource "counter" Int, HasSink "counter" Int, HasState "counter" Int) via
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside the scope of this PR, but I wonder if there's a way to avoid this boilerplate of explicitly deriving all superclasses. From a user's perspective that's a cost of the finer grained class hierarchy. And it means that adding a new superclass will often break user's code.

Maybe that's really an issue with deriving-via. cc @aspiwack

This may be a terrible idea, but just to throw it out. For the user facing capabilities we could group all superclasses together into a synonym (or type family) like so:

class (HasSourceClass tag a, HasSinkClass tag a) => HasStateClass tag a where ...
type HasState tag a = (HasSourceClass tag a, HasSinkClass tag a, HasStateClass tag a)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this packing of classes would work: you can only derive type classes, not conjunctions of them.

And, generally, yes: adding subclasses breaks code. It is true that, in this case, it means that every derivation of State need to be somewhat triplicated. Which is not very nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is a downside I didn't know how to fix. I'm not sure about the ramifications of super and subclasses from different newtypes with derive-via; Whether that is possible affects whether making one list them all adds any information.

We now have:

```
    Source   Sink
    /   \    /   \
   /     \  /     \
Reader   State    Writer
```

HasStream has been renamed (with deprecated aliases for compatibility) to HasSink, to
illustrate the symmetry.

Co-Authored-By: Andreas Herrmann <andreash87@gmx.ch>
@aherrmann
Copy link
Member

@Ericson2314 Thanks for implementing this! I'm merging now, sorry for the delay. A Source example would still be nice to have, but it can go into a separate PR.

@aherrmann aherrmann merged commit b7d64d5 into tweag:master Jul 10, 2019
@Ericson2314
Copy link
Contributor Author

Ericson2314 commented Jul 10, 2019

Oh thank you! Sorry I didn't get it to you already, I had this tab open as a TODO. I'll keep this tab open as a TODO.

@Ericson2314 Ericson2314 deleted the stream-reader branch July 10, 2019 22:17
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

Successfully merging this pull request may close these issues.

Elimination methods in classes should be moved

3 participants