
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? Thanks; Jamie -- View this message in context: http://www.nabble.com/Sorting-Integers-t1113340.html#a2908719 Sent from the Haskell - Haskell-Cafe forum at Nabble.com.

jamie.edwards:
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?
Prelude> let sort3 x y z = List.sort [x,y,z] Prelude> sort3 8 2 0 [0,2,8] Cheers, Don

On 2/13/06, JimpsEd
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. /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862

On 2/13/06, Sebastian Sylvan
On 2/13/06, JimpsEd
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]) -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862

sebastian.sylvan:
On 2/13/06, Sebastian Sylvan
wrote: On 2/13/06, JimpsEd
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 :)
participants (3)
-
dons@cse.unsw.edu.au
-
JimpsEd
-
Sebastian Sylvan