
Hi, I see the type of the List.sort function is: Ord a => [a] -> [a] I don't understand how this type can allow it to sort pairs: Prelude> :m +List Prelude List> sort [(1, "1"), (3, "3"), (2, "2")] [(1,"1"),(2,"2"),(3,"3")] How can a pair by of type "Ord a"? Is it a rule that the first element is automatically used? Patrick -- ===================== Patrick LeBoutillier Rosemère, Québec, Canada

instance (Ord a, Ord b) => Ord (a,b) where compare (x,y) (z,w) = case compare x z of EQ -> compare y w c -> c Not certain that's the exact code that's used, but it's close enough. Bob On 11 Jul 2009, at 15:06, Patrick LeBoutillier wrote:
Hi,
I see the type of the List.sort function is:
Ord a => [a] -> [a]
I don't understand how this type can allow it to sort pairs:
Prelude> :m +List Prelude List> sort [(1, "1"), (3, "3"), (2, "2")] [(1,"1"),(2,"2"),(3,"3")]
How can a pair by of type "Ord a"? Is it a rule that the first element is automatically used?
Patrick
-- ===================== Patrick LeBoutillier Rosemère, Québec, Canada _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (2)
-
Patrick LeBoutillier
-
Thomas Davie