3 ms·
It'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 kno
by the_af 11y ago
It'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.