[Haskell-cafe] List as input
leimy2k at gmail.com
Thu Oct 16 09:29:57 EDT 2008
On Wed, Oct 15, 2008 at 9:53 PM, leledumbo <leledumbo_cool at yahoo.co.id>wrote:
> > The compiler doesn't know what kind of list you are trying to read,
> sort, and print.
> So, the type must be specific? Then why it's possible to call the sorting
> function with any list?
It isn't. The type of data in the list must be able to be compared.
See the type signature for Data.List.sort
Data.List.sort :: (Ord a) => [a] -> [a]
So "any" list may be sorted if the items in the list are of Ord.
> > I'm curious as to why taking the pivot from the middle is an
> 'optimized' version.
> Consider if it's used in a GUI program which calls the function when a
> button is pressed. Often, users clicks the button more than once. If the
> pivot is the first (or last) element, the second (and further) click will
> cause worst case scenario to happen. OTOH, if the pivot is the middle
> element, best case scenario will happen.
> View this message in context:
> Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe