VinylRecords / Vinyl

Extensible Records for Haskell. Pull requests welcome! Come visit us on #vinyl on freenode.
http://hackage.haskell.org/package/vinyl
MIT License
261 stars 49 forks source link

Re-implement rIso? #26

Closed conklech closed 10 years ago

conklech commented 10 years ago

The lens removal (#23) left rIso commented out, so you can't actually do anything with the knowledge that r1 :~: r2. (Edit: This is of course wrong; you can cast both ways.)

To export a lens-compatible Iso', we need to incur a dependency on profunctors. (See the lens wiki.) Alternately, we could export cast. (Edit: We've always exported cast.)

-- | In 'lens' parlance,
--
-- > rIso :: (r1 :~: r2) => Iso' r1 r2
rIso :: (r1 :~: r2, Profunctor p, Functor f) => p r1 (f r1) -> p r2 (f r2)
rIso = dimap cast (fmap cast)
acowley commented 10 years ago

First, thanks for this. This is clearly the right way to provide a lens-compatible iso. In general, though...

Is this a useful definition? I'm honestly not sure, which is why it is distinguished by living in a zombie commented out state. We do export cast, so the potential user is not stranded, but losing the definition didn't impact me at all. So we can add a profunctors dependency to support this definition, or we could make rIso part of the documentation.

If we pick up a profunctors dependency for other reasons, then this is a nice thing for vinyl to define.

conklech commented 10 years ago

...you're right. We've always exported cast, and rIso is dramatically less useful than cast. Sorry, my brain wasn't turned on.

The use case for rIso does seem a bit improbable. Perhaps libraryA uses Rec '["foo" ::: t, "bar" ::: t] and libraryB uses Rec '["bar" ::: t, "foo" ::: t] and you want to interoperate between them?

jonsterling commented 10 years ago

Casting should suffice for records which have different order, I think... Is there any other use-case we'd like to address?

acowley commented 10 years ago

I'm going to close this for now, but it should be reopened if more evidence for rIso's usefulness comes to light.