This code works, but it is verbose, and I'm sure there is a more concise way.
import qualified Data.Vector as V
data Event a = Event { start :: Time
, duration :: Time
, payload :: Maybe a } deriving (Show, Eq)
instance Ord a => Ord (Event a) where
(<=) a b = start a < start b
|| start a == start b && duration a < duration b
|| start a == start b && duration a == duration b && payload a <= payload b
The idea is that if one thing starts earlier than the other, you should call it less and don't even look at the other two fields. Similarly, if they start at the same time, but one is shorter, then this one is shorter than less, and you can ignore the third field.
source
share