[Haskell-beginners] Re: let indenting problems
bbxx789_05ss at yahoo.com
Mon Mar 2 15:08:19 EST 2009
Heinrich Apfelmus <apfelmus <at> quantentunnel.de> writes:
> How about
> import Data.Ord (comparing)
> mySort = sortBy (comparing length)
I just finished chap. 3 of Real World Haskell, which doesn't
even imports. It took me hours to figure out how to
access sortBy. The book hasn't introduced "comparing", yet.
> or at least
> mySort = sortBy myCompare
> myCompare x y = compare (length x) (length y)
Very nice. The book mentioned the compare function in
I have a question about that code: how come you
don't have to specify a parameter for mySort, for example:
mySort xs = ...
And doesn't sortBy require two arguments?
sortBy :: (a -> a -> Ordering) -> [a] -> [a]
How come you can write it with only one argument?
Finally, l'm wondering if anyone can explain why my
let examples failed?
More information about the Beginners