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

Split up store typeclass #21

Open
mgsloan opened this issue May 14, 2016 · 2 comments
Open

Split up store typeclass #21

mgsloan opened this issue May 14, 2016 · 2 comments

Comments

@mgsloan
Copy link
Owner

mgsloan commented May 14, 2016

What if we split up the store typeclass into separate poke and peek portions? There are a couple reasons for this:

  • store is already useful for defining serialization and deserialization for existing binary formats, even though this wasn't our immediate goal. For these applications, you might only care about reading or writing some particular data, and not both. I think @chrisdone in particular will agree this should be split up.
  • I suspect that the approach for speeding up compilation time described in Compilation for big datatypes with Generics is quite slow #5 is not just specific to generics, and may apply to any multi method typeclass (maybe only in the presence of aggressive inlining?). This remains to be measured.

So, to me, it seems like we should split it up. The only downside is that it takes a bit more boilerplate to define both instances, even with generics. However, the TH magic should be able to be just as concise.

All that's left is bikeshedding. What do we call these classes? Maybe something like:

-- Constraint synonym
type Store a = (Peekable a, Pokeable a)

class Peekable a where peek :: Peek a
class Pokeable a where
    size :: Size a
    poke :: a -> Poke ()

Other possibilities are StorePeek and StorePoke, or instead perhaps HasPeek and HasPoke.

It may even be worthwhile to split out the size method, but I think I prefer it bundled with poke, since that's what it's used for.

@snoyberg @chrisdone @kantp @bitonic Thoughts on this bikeshed? :)

@chrisdone
Copy link
Contributor

chrisdone commented May 14, 2016

I'm fine with Peekable/Pokeable. One of our clients has indeed a codebase which has a Peek but no Poke.

@kantp
Copy link
Contributor

kantp commented May 17, 2016

I'd be more than happy if this would indeed speed up the compilation!

As for the bikeshedding, I agree that Peekable/Pokeable is fine.

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

No branches or pull requests

3 participants