Is there some Haskell extension that enables the creation of more complex data constructors then GADT?
Suppose I wanted to create a data structure that is an ordered list, and have a data constructor similar to (:)
that work with lists, with type signature:
data MyOrdList a where
(>>>) :: (Ord a) -> a -> MyOrdList a -> MyOrdList a
But I want (>>>)
to have a specific behavior, something like this:
(>>>) :: (Ord a) => a -> [a] -> [a]
x >>> [] = [x]
x >>> xs = low ++ [x] ++ high
where low = filter (<x) xs
high = filter (>x) xs
So the structure will be always an ordered structure. (I don't now if this is a good practice, I'm just offering the simplest example that occurred me of the type of behavior I want).
Of course I can use a function (>>>)
, but then I'll have no pattern matching and other benefits I'd have it >>>
was a data constructor.
Is there any way to do something like this?