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

Add getDown #68

Open
phadej opened this issue Mar 27, 2020 · 5 comments
Open

Add getDown #68

phadej opened this issue Mar 27, 2020 · 5 comments

Comments

@phadej
Copy link
Contributor

phadej commented Mar 27, 2020

Needs Data.Ord.Compat module

@RyanGlScott
Copy link
Member

Hm. At the moment, there is a list of things that base-compat declares as out of scope for the project, since backporting them would be unrealistic. Currently, that list of things includes data types and classes. Record selectors, such as getDown, are not mentioned at the moment, but I wonder if they should be included as well. We could certainly "backport" getDown like so:

getDown :: Down a -> a
getDown (Down x) = x

But this is only a half-measure, since you wouldn't be able to use this backported form of getDown in record syntax. Given this, I wonder if adding this is even worth it.

@phadej
Copy link
Contributor Author

phadej commented Mar 27, 2020

I used it in code which looks like:

src/Topograph.hs-transpose G {..} = G
src/Topograph.hs-    { gVertices     = map Down $ reverse gVertices
src/Topograph.hs:    , gFromVertex   = gFromVertex . getDown
src/Topograph.hs-    , gToVertex     = fmap Down . gToVertex

I'd prefer it in base-compat than CPPing it (as I do now). I doubt anyone would use an update syntax for Down, it doesn't really make sense:

d { getDown = 12 }
-- is the same as just
Down 12

i.e. it's not perfect shim, but better than no-shim.

@phadej
Copy link
Contributor Author

phadej commented Mar 27, 2020

Also, https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#record-pattern-synonyms if you really insist ;) but I'd be quite happy with just pseudo-selector function. (I wonder why it was added a selector functions, if there's some "measurable" benefit).

@RyanGlScott
Copy link
Member

i.e. it's not perfect shim, but better than no-shim.

True. As long as some part of base-compat's documentation makes it clear that backported record selectors do not participate in record syntax, then I suppose I could live with this. Would you be willing to offer a PR?

@phadej
Copy link
Contributor Author

phadej commented Mar 27, 2020

Will do, not immediately though.

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

2 participants