3 ms·
Yes but by using mkSegment in the implementation of intersect, you have to treat its Nothing result, even though it can never happen and so you either end up wi
by bad_user 11y ago
Yes but by using mkSegment in the implementation of intersect, you have to treat its Nothing result, even though it can never happen and so you either end up with this reflected in the signature of intersect itself, or you cheat in the implementation of intersect by assuming that Nothing will never happen, which would defeat the purpose of mkSegment.
- the_af 11y agoIt's a bit cumbersome, yes, but I don't think it defeats the purpose of mkSegment. Let's see: because mkSegment is the only way to construct a Segment, you know the arguments to intersect are valid. So there cannot be any doubt about the meaning of Maybe in the result; it simply cannot refer to invalid arguments. There is only one other possible meaning: that the segments don't intersect, which is the idiomatic use of Maybe (another reason why I wouldn't use Maybe in this case to signal an invalid argument: "which argument?"). Yes, this means that even if there is an intersection, mkSegment forces you to handle the None case, even though you know by construction this will never happen. It's annoying but nothing too terrible. I don't see how this is cheating; you are simply using a property that the type system is unable to catch... but this property exists nonetheless.