In functional optics, a well-behaved prism (called a partial lens in scala, I believe) is supposed to have a set function of type 'subpart -> 'parent -> 'parent
, where if the prism "succeeds" and is structurally compatible with the 'parent
argument given, then it returns the 'parent
given with the appropriate subpart modified to have the 'subpart
value given. If the prism "fails" and is structurally incompatible with the 'parent
argument, then it returns the 'parent
given unmodified.
I'm wondering why the prism doesn't return a 'parent option
(Maybe
for Haskellers) to represent the pass/fail nature of the set function? Shouldn't the programmer be able to tell from the return type whether the set was "successful" or not?
I know there's been a lot of research and thought put into the realm of functional optics, so I'm sure there must be a definitive answer that I just can't seem to find.
(I'm from an F# background, so I apologize if the syntax I've used is a bit opaque for Haskell or Scala programmers).
Just
actually aRight
? – Photina