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 coercion Iso #579
Comments
A slightly prettier expression: coercionToIso' c = rmap (fmap . coerceWith $ sym c) . lmap (coerceWith c) |
Ah, but the prettier one is probably lazy in an unfortunate way. |
The major concern I'd have about such a combinator is how bad inference will be when using it in practice. Using iso coerce coerce' :: (Coercible t b, Coercible s a) => Iso s t a b Using |
There are a few options for the more general combinator, unfortunately. One is to use the fact that coercibleIso1 :: forall s t a b . (Coercible t b, Coercible s a) => Iso s t a b
coercibleIso1 = dimap coerce (fmap (coerce (id :: t -> t))) we could use coercibleIso2 :: forall s t a b . (Coercible b t, Coercible s a) => Iso s t a b
coercibleIso2 = dimap coerce (fmap coerce) Inference does seem likely to be on the poor side, but I don't think that's a reason to exclude these—someone who wants one can just use a type signature. The coercibleIso' :: forall a b . Coercible a b => Iso' a b
coercibleIso' = dimap coerce (fmap (coerce (id :: a -> a))) seems likely to offer considerably better inference. I am a bit concerned about the core I see without specialization. I get
with the |
Using The combinators that consume a getter all do that unification for you. This is why |
We can optimize this further by using something like coerce #. lmap (fmap coerce') This will lift the one |
Makes sense, although I still don't understand why the |
I couldn't find anything like this, which of course doesn't mean there isn't such.
It might also be useful to offer this "out of the air" version:
The text was updated successfully, but these errors were encountered: