It sounds like a use case for ViewPatterns
. You could write a type like:
data ViewPartialOrder a = ViewPartialOrder a (a -> a -> Ordering)
Write a function like:
viewOrder :: PartialOrder -> ViewPartialOrder
viewOrder (PartialOrder xs relation) = ...
then use the ViewPatterns
extension to write code like this:
f (viewOrder -> ViewPartialOrder xs le) = ...
Of course, you should come up with better names for these things :P!
There's no way to have the same effect implicitly (ie without the viewOrder
function), for better or worse. I think it's usually a good thing, making it clear that you're not matching the actual implementation of the type.