Lens / Prism with error handling

大城市里の小女人 提交于 2019-12-03 11:00:19

I have recently written a blog post about indexed optics; which explores a bit how we can do coindexed optics as well.

In short: Coindexed-optics are possible, but we have yet to do some further research there. Especially, because if we try to translate that approach into lens encoding of lenses (from Profunctor to VL) it gets even more hairy (but I think we can get away with only 7 type-variables).

And we cannot really do this without altering how indexed optics are currently encoded in lens. So for now, you'll better to use validation specific libraries.

To give a hint of the difficulties: When we try to compose with Traversals, should we have

-- like `over` but also return an errors for elements not matched
validatedOver :: CoindexedOptic' s a -> (a -> a) -> s -> (ValidationErrors, s)

or something else? If we could only compose Coindexed Prisms their value won't justify their complexity; they won't "fit" into optics framework.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!