-
Notifications
You must be signed in to change notification settings - Fork 24
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
Optics.Coerce isn't zero-cost #351
Comments
I thought that we can have newtype Re p s t i a b = Re { unRe :: p i b a -> p i t s } screws that idea. i.e. we either have to be "Coercible1" in both parameters |
I had a play with this (branch type Coercible1 f = (forall a b . Coercible a b => Coercible (f a) (f b)) :: Constraint
type Coercible2 f = (forall a a' b b' . (Coercible a a', Coercible b b') => Coercible (f a b) (f a' b')) :: Constraint
type Coercible3 f = (forall a a' b b' c c' . (Coercible a a', Coercible b b', Coercible c c') => Coercible (f a b c) (f a' b' c')) :: Constraint but there are a few problems:
I don't think this is a feasible approach now, but maybe in 10 years... |
I think that the latter is a myth. See https://oleg.fi/gists/posts/2019-07-31-fmap-coerce-coerce.html#functor-should-be-parametric |
@phadej interesting, thanks. I knew I had seen something discussing this before, but a quick search turned up only Ryan's post. Still, given how long AMP took, I can't imagine a |
@phadej the only practical concern with wrapping a |
The current implementations of the
coerce{S,T,A,B}
functions inOptics.Coerce
sometimes require traversing data structures and hence are not guaranteed to be zero-cost, unlikecoerce
. For example we haveAt the very least we should make it clear in the
Optics.Coerce
docs that coercion may involve a runtime cost. But perhaps it is possible to do better. For example, can we useQuantifiedConstraints
onCoercible
to fake a limited version of higher-order roles?The text was updated successfully, but these errors were encountered: