[Haskell-cafe] Sorting Integers
Donald Bruce Stewart
dons at cse.unsw.edu.au
Mon Feb 13 06:42:04 EST 2006
> On 2/13/06, Sebastian Sylvan <sebastian.sylvan at gmail.com> wrote:
> > On 2/13/06, JimpsEd <jamie.edwards at gmail.com> wrote:
> > >
> > > I have 3 integers, a b c that I want to pass to a function, and I want the
> > > function to return the 3 integers sorted, from largest to smallest - any
> > > idea how to do this?
> > >
> > Well, the obvious way
> > import Data.List
> > foo a b c = (a',b',c')
> > where [a',b',c'] = sort [a,b,c]
> > This sounds like some type of "exercise" task though, so I think they
> > may be looking for something using guards and several comparisons.
> Oops, you'd need to reverse the sorted list if you want largest to smallest.
> foo a b c = (a',b',c')
> where [a',b',c'] = reverse (sort [a,b,c])
Oh, I made the same mistake. Jinx!
-- Don :)
More information about the Haskell-Cafe