haskell-compat / base-compat

A compatibility layer for base
http://hackage.haskell.org/package/base-compat
19 stars 12 forks source link

Add getDown #68

Open phadej opened 4 years ago

phadej commented 4 years ago

Needs Data.Ord.Compat module

RyanGlScott commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Will do, not immediately though.