phadej / hkd

"higher-kinded data"
Other
4 stars 0 forks source link

Add FFunctorWithIndex (and possibly a class for constraints) #8

Open Jashweii opened 3 years ago

Jashweii commented 3 years ago
-- compare to lens' functor with index
class FFunctor f => FFunctorWithIndex i f | f -> i where
  iffmap :: (forall x . i x -> a x -> b x) -> f a -> f b

This can be very useful for HKDs if the index type reveals something about the parameter (e.g. if the index type is a GADT or has a context). If the index type is (Dict1 c) then we can map assuming c for the foralled parameter. If the HKD applies specific types/type level values to its parameter, its index might be a GADT that allows switching on those types.

It may be better to leave off the fundep and allow multiple index types, or introduce another class for the specific case of i = Dict1 c.

class FFunctor f => FFunctorSatisfies c f where
  assuming :: (forall x . c x => a x -> b x) -> f a -> f b
-- ambiguous type, intended use is with c explicitly applied

-- assuming @Read (readMaybe . getConst)
-- :: FFunctorSatisfies Read t => t (Const String) -> t Maybe
phadej commented 3 years ago
class FFunctor f => FFunctorWithIndex i f | f -> i where
  iffmap :: (forall x . i x -> a x -> b x) -> f a -> f b

is reasonable. I'll add that and FTraversable etc analogues..