[Haskell-beginners] Comparison between fields of each record

Dimitri DeFigueiredo defigueiredo at ucdavis.edu
Tue Nov 24 18:57:58 UTC 2015


I don't understand your question but the class Ord in Data.Ord is our 
tool for comparisons. You may want to look into that. You can also
use the function "on" from Data.Function to compare on a specific record 
within a larger structure.

Dimitri


On 11/24/15 11:20 AM, Jeon-Young Kang wrote:
> Dear All.
>
> I'd like to compare fields of each record.
>
> here is my record.
>
> data Person = Person {name:: String, age:: Int } deriving(Show)
> data Relations = Friend | Older | Younger
>
> class Comparison a where
>     compare:: a -> a -> Relations
>
> instance Comparison Person where
>     compare Person a b Person a b
>          | b1 == b2 = Friend
>          | b1 > b2 = Older
>          | b1 < b2 = Younger
>
> How can I fit it?
>
> Sincerely,
>
> Jeon-Young Kang
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151124/4fa80ba9/attachment.html>


More information about the Beginners mailing list