Writing profunctor optics by the same template

1 Like

FYI, the optics library uses profunctor representation internally.

1 Like

Of course, I know that. Here I just wanted to obtain all optics uniformely, following the same template, minimizing a “guessing” component.

Very interesting! I wonder if you can abstract out the common pattern, something like

class OpticC opticP p where
  opticOp :: opticP a b s t -> p a b -> p s t

type AnOptic' opticP s t a b = AnOptic (opticP a b) s t a b

I don’t know how to get the nice optic hierarchy subtyping with that approach though. Perhaps there’s a trick to make it work.

1 Like

I found the way to do this. Maybe there is more clear one. Is it useful – I don’t know. Also I’m not sure, that we’ll don’t have any runtime overhead.

1 Like