[Haskell-beginners] Why do i need to specify the class of a here at all?

Patrik Iselind patrik.mrx at gmail.com
Wed Nov 22 21:15:59 UTC 2017


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: exercises.hs
Type: text/x-haskell
Size: 1007 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20171122/4504ad3e/attachment.hs>


More information about the Beginners mailing list