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
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)
The only problem I can see with this definition is that if you hadn't previously defined min2 and max2, then it would fail, since these aren't in the prelude. However, if you replace those with min and max, it seems to work fine. I assume that you had to define min2 and max2 previous in your exercise. Maybe you could post those definitions as well as what the problem you're encountering is. -- Irfon-Kim Ahmad http://members.home.com/irfon/ahmadi/
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.
participants (3)
-
Hannah Schroeter -
Irfon-Kim Ahmad -
Swee Guan