
11 Oct
2014
11 Oct
'14
10:04 a.m.
"Nicolaas du Preez":
data Cycle = Cycle { name :: String, size :: Double } deriving (Eq, Show)
instance Ord Cycle where (<) a b = (<) (size a) (size b) -- problem statement! …
How can I specify that, on the right-hand side of the problem statement,
I refer to (<) :: Double -> Double -> Bool instead of (<) :: Cycle -> Cycle -> Bool?
Is there another way to state that "Cycle is an instance of Ord based on
size"?
There is the `on` function in Data.Function which allows you to express such correlation. On a side note, you probably just want to implement `compare` so all the other functions of the Ord type class can be derived from it. -- Nadir