Is it possible to provide a custom pattern decomposition in Haskell?

Viewed 685

In Haskell, I have a module with a partial order type:

data PartialOrder a = PartialOrder [a] [(a, a)]

I don't export the value constructor because that's not how I want the type to be used, but I still want to be able to pattern match the PartialOrder type outside the module; is this possible? In particular, I want to be able to pattern match something that is not the type constructor, but instead, to pattern match something like the following:

f (PartialOrder xs le) = ...

Where le is a function implicitly defining the explicit ordering defined in the value constructor. I know such a facility is available in Scala, is there a way to do the same in Haskell?

Thanks in advance.

2 Answers
Related