Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Should we change the API for holesOf? #252

ekmett opened this Issue Jan 19, 2013 · 1 comment


None yet
2 participants

ekmett commented Jan 19, 2013

Right now holesOf returns a list of editable contexts.

This was fine in our old understanding of traversals, but now we realize this causes us to have to do lots of unnecessary reassociating, introducing bottoms that dont need to be present.

We could have it provide a Traversal that looks something like:

holesOf :: (Conjoined p, Applicative f) => Over p (HolesOf p f a) s t a a
        -> Over p f s t (Pretext p a a t) (Pretext p b a u)

which could be done without introducing the reassociation bias, and then the user can use

foo^..holesOf traverse

to enumerate the holes if they want them the current way anyways.

@ghost ghost assigned ekmett Jan 19, 2013


glguy commented Jan 22, 2015

I started playing this this and I got to this point. I'm adding it to the ticket so it doesn't get lost.

myHolesOf ::
  forall i p f s t a b u.
  (Indexable i p, Applicative f) =>
  Over (Indexed i) (Molten i a a) s t a a ->
  Over p f s t (Pretext' p a t) (Pretext p a b u)
myHolesOf t f x = n
  -- wrap user's operation ignoring the unfocused result
  f' :: p (Pretext p a a t) (f a)
  f' = rmap (fmap ipos) f

  -- reify the traversal
  o :: Magma i t a a
  o = runMolten (t sell x)

  -- transform the reified traversal to store pretexts at leaves
  p :: Bazaar p (Pretext p a a t) a t
  p = magmaPretext o runMagma

  -- run the reified traversal transforming the pretexts to results
  n :: f t
  n = bazaar f' p

magmaPretext ::
  Indexable i p =>
  Magma i t b a -> (Magma i t b a -> z) ->
  Bazaar p (Pretext p a a z) b t

-- Functor operation
magmaPretext (MagmaFmap f x) k = fmap f (magmaPretext x (k . MagmaFmap f))

-- Applicative operations
magmaPretext (MagmaPure x) _   = pure x
magmaPretext (MagmaAp mf mx) k = magmaPretext mf (k . (`MagmaAp`mx))
                             <*> magmaPretext mx (k . (mf`MagmaAp`))

-- Primitive operation
magmaPretext (Magma i x) k     = indexed sell i (fmap (k . Magma i) (indexed sell i x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment