1
votes

I was browsing the 'lens' documentation concerning prisms, and I noticed a line in Control.Lens.Review stating that the infix review operator # 'is commonly used when using a Prism as a smart constructor.'.

This got my a bit intrigued, because the example with _Left, one of constructor for the 'Either' data type didn't seem like a smart constructor as far as I understand smart constructors (adding extra restrictions on argument values). So I googled around a bit for prisms as smart constructors but I didn't really find any example.

Is there someone who knows what exactly is meant with this statement and might give an example? Or maybe tell me that my definition of smart constructor is not correct, of course.

1

1 Answers

2
votes

One view of the Prism type is as a near-isomorphism. In fact, the lens documentation says "It may help to think of this as a Iso that can be partial in one direction."

And isn't the partial direction a pretty good analogy for a smart constructor? You can hand it any set of arguments (that match the type), but some of them will fail to create a value.