[Haskell-beginners] "Delegating" class instance definition

Nicolaas du Preez njdupreez at yahoo.com
Sat Oct 11 17:16:36 UTC 2014


Thanks for the reply - since you mentioned that it should work I figured there must’ve been a mistake somewhere else.

Looking closer I realised that when I copied & pasted the definition for (<) to the rest of the functions and the problem actually occurred at
	...
	max a b = max (size a) (size b)
	min a b  = min (size a) (size b)
	…
which has return type of Double where it should be Cycle.

Regards,
Nicolaas

On 11 Oct 2014, at 15:39, Brandon Allbery <allbery.b at gmail.com> wrote:

> 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
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20141011/1f4c0205/attachment.html>


More information about the Beginners mailing list