Lens / Prism with error handling

前端 未结 1 587
無奈伤痛
無奈伤痛 2021-02-07 05:01

Let\'s say I have a pair of conversion functions

string2int :: String -> Maybe Int
int2string :: Int -> String

I could represent these f

1条回答
  •  礼貌的吻别
    2021-02-07 05:45

    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.

    0 讨论(0)
提交回复
热议问题