
Hi Patrik, The reason for the requirement of “Eq a” in your `sortListOfLists` is that you are calling myOrderFunc which carries the signature “Eq a”. If you remove the `Eq` declaration in `myOrderFunc` the compiler then would not complain about the absence of `Eq` in `sortListOfLists`. For a detailed explanation you could reference chapter 6 of Real World Haskell. Yes, you could pass the function a list of strings as well. A string is just a list of Chars. The type signature `a` does not restrict the range of types you could pass to the function. A list of lists of lists would even work. e.g.
ghci> sortListOfLists [["hello"], ["this", "is"], ["just", "a", "test”]] [["hello"],["this","is"],["just","a","test"]]
Regards,
Qingbo Liu
On Nov 22, 2017, 16:17 -0500, Patrik Iselind
Hi,
I'm following the Real World Haskell book and in chapter three came across the exercise to sort a list of lists. I attach what i have so far.
My question is the following. Why do i need to add "Eq a =>" to the type definition of sortListOfLists? The type of a should be irrelevant as i see it, my function couldn't care less what the type of the contents of the lists in the list are, or? All my function cares about is the length of those lists in the list. The designator a in the type declaration for sortListOfLists denote the type of the contents in the lists of lists as i understand it. So a list of lists containing object i can test for equality.
Another thought i have is if i really have to specify that i expect list of lists. Couldn't that be list of something else with a length, a string perhaps, just as well? In other words a type like sortListOfLists :: a -> a. As i see it that should be just as valid as the type of what i return is the same as that which i get as input regardless of it being a list or not.
-- Patrik Iselind
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners