21 Mar
2001
21 Mar
'01
4:30 p.m.
Hello! On Tue, Mar 20, 2001 at 05:13:12PM +0800, Swee Guan wrote:
I was suppose to find a function mid3 that takes three integers and returns the middle one in terms of size but i cant seem to get it. maybe you can help
mid3 :: Int -> Int -> Int -> Int -- mid3 takes three integers and -- returns the middle one in terms of size mid3 x y z = min2 x (max2 y z)
please send to swigs01@hotmail.com
This is plain wrong. 1st, min2 and max2 aren't defined (use min and max from the prelude). 2nd, then, mid3 1 2 3 = min 1 (max 2 3) = min 1 3 = 1, instead of 2. A simple implementation could be: import List(sort) mid3 x y z = (sort [x,y,z]) !! 1 Kind regards, Hannah.