[Haskell-beginners] "Delegating" class instance definition

Brandon Allbery allbery.b at gmail.com
Sat Oct 11 13:39:48 UTC 2014


On Sat, Oct 11, 2014 at 9:02 AM, Nicolaas du Preez <njdupreez at yahoo.com>
wrote:

> 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?
>

That should be automatic, since it knows that size :: Cycle -> Double and
therefore should use the Double instance. Can you provide a minimal full
example and full error message?

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20141011/d5f847bf/attachment.html>


More information about the Beginners mailing list