Open treeowl opened 7 years ago
You mention the type class Ixed
with a Lens
, this page on the wiki Varying lens properties by instance shows a funny approach
class Ixed_ xs where
type IxedConstraint_ xs :: (Type -> Type) -> Constraint
type IxedConstraint_ xs = Applicative
ix_ :: Index xs -> IxedConstraint_ xs f => LensLike' f xs (IxValue xs)
indicated by a newtype
newtype WrappedIxedRep r a = WrapIxedRep (r a)
deriving newtype
(Functor, Representable)
instance Representable r => Distributive (WrappedIxedRep r) where
distribute = distributeRep
type instance IxValue (WrappedIxedRep r a) = a
type instance Index (WrappedIxedRep r a) = Rep r
instance (Representable r, Eq (Rep r)) => Ixed_ (WrappedIxedRep r a) where
type IxedConstraint_ (WrappedIxedRep r a) = Functor
ix_ :: Rep r -> Lens' (WrappedIxedRep r a) a
ix_ = ixSureDef
In general,
Of course, this is horrifically inefficient. Is there a good place here for a subclass supporting such an operation? Alternatively (or additionally), is there room in lens for an
IxSure
class similar toIxed
but providing aLens
instead of aTraversal
?