Skip to content
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

The gather function fails to memoise some actions #1

Open
viercc opened this issue Nov 9, 2021 · 1 comment
Open

The gather function fails to memoise some actions #1

viercc opened this issue Nov 9, 2021 · 1 comment

Comments

@viercc
Copy link

viercc commented Nov 9, 2021

Memorizing an action to compute a field of the HKD type t is done only when it's queried using hitchF. Because gather calls actions directly, evaluating gather can perform the action for a field up to 2 times (the field itself and as a dependency via hitchF.)

Unless it's going to be removed, I think one way to get rid of the duplications in gather is requiring a record of lenses to the field itself, like this:

newtype LensB t a = LensB
  { toVLLens :: forall g h. Functor g => (h a -> g (h a)) -> t h -> g (t h) }

class HasSelfLenses t where
    selfLenses :: t (LensB t)

gather :: (TraversableB t, HasSelfLenses t, Monad m) => TangleFT t f m (t f)
gather = btraverse (\l -> hitchF (toVLLens l)) selfLenses

HasSelfLenses is very ad hoc of course. I'm not very confident, but they seem to be related to Representable.

class RepresentableB (t :: (k -> Type) -> Type) where
    data Key t :: k -> Type
    bindex :: Key t a -> t f -> f a
    btabulate :: (forall a. Key t a -> f a) -> t f
@fumieval
Copy link
Owner

fumieval commented Nov 9, 2021

Good point. barbies-th has AccessosB so I guess it's easiest to use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants