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

Documenting gread / GReadS #32

Open
infinity0 opened this issue Apr 9, 2020 · 1 comment
Open

Documenting gread / GReadS #32

infinity0 opened this issue Apr 9, 2020 · 1 comment
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed

Comments

@infinity0
Copy link
Member

I think it would make things clearer to document gread as being in continuation-passing style. I literally only just realised this now, because it was similar to some other code I wrote today. And now I finally understand that type GReadS t [*] is something that consumes the continuation, which is vital to understanding how to implement an instance of GRead. (Previously I was just copy-pasting the existing instances and fiddling around until the type errors went away.)

[*] Actually this refers to the previous implementation of GReadResult, today's implementation avoids CPS and is a bit clearer, however the docstring still refers to the old CPS implementation which could still confuse users.

gread is still in CPS though and should be documented as such. Also, an alternative offering which may be more convenient for some users would be:

{-# LANGUAGE QuantifiedConstraints #-}

newtype SomeCxt c = SomeCxt { unCxt :: forall v. c v => v }

greadC
  :: (GRead t, forall a. c (t a))
  => Proxy t
  -> String
  -> SomeCxt c
greadC = ...

This relies on there existing an appropriate instance that applies to all a, which may not always exist, but if it does then it could be more convenient to use than passing in a continuation.

@phadej phadej added documentation Improvements or additions to documentation help wanted Extra attention is needed labels Apr 9, 2020
@phadej
Copy link
Collaborator

phadej commented Apr 9, 2020

I added appropriate labels to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants