I’ve thought that Prism optics are mainly about navigating sum types, but the readily-available examples are about things like going from natural numbers to integers or showing the use of predefined prisms. Is that because defining Prisms for sum types is tedious?
Consider this sum type:
data Fill
= Solid Color
| LinearGradient Color Color Percent
| RadialGradient Color Color Point
| NoFill
Is there a less cumbersome way to define a Prism for the Solid
case than this?
chooseSolidM fill =
case fill of
Solid x -> Just x
_ -> Nothing
solidM = prism' Solid chooseSolidM
… or the variant using Either
:
chooseSolidE fill =
chooseSolidM fill # note fill
solidE = prism Solid chooseSolidE