Is there some kind of Haskell extension that allows you to create more complex data constructors, then GADT?
Suppose I wanted to create a data structure that is an ordered list, and have a data constructor like (:) that works with lists with a signature type:
data MyOrdList a where (>>>) :: (Ord a) -> a -> MyOrdList a -> MyOrdList a
But I want (>>>) 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
Thus, the structure will always be an ordered structure. (I’m not right now, if this is good practice, I’m just offering the simplest example that called me out by the type of behavior I want).
Of course, I can use the function (>>>) , but then I will not have the pattern matching and other advantages that I would have with it. >>> was a data constructor.
Is there a way to do something like this?
source share