Created
July 13, 2014 15:55
-
-
Save CarloMicieli/e5436a3f2a0cfca5be58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
twoLargest :: (Num a, Ord a) => a -> a -> a -> (a, a) | |
twoLargest x y z | |
| x <= y && x <= z = (y, z) | |
| y <= x && y <= z = (x, z) | |
| otherwise = (x, y) | |
square :: (Num a) => a -> a | |
square x = x * x | |
squarePair :: (Num a) => (a, a) -> (a, a) | |
squarePair (f, s) = (square f, square s) | |
sumPair :: (Num a) => (a, a) -> a | |
sumPair (f, s) = f + s | |
sumSquareTwoLargest :: (Num a, Ord a) => a -> a -> a -> a | |
sumSquareTwoLargest x y z = sumPair $ squarePair $ twoLargest x y z | |
secondLargest :: (Num a, Ord a) => a -> a -> a -> a | |
secondLargest x y z = min (fst p) (snd p) | |
where p = twoLargest x y z | |
p :: Int -> Int | |
p x = p x | |
test :: Int -> (Int -> Int) -> Int | |
test x y = if x == 0 then 0 else (y x) | |
max3 :: (Num a, Ord a) => a -> a -> a -> a | |
max3 x y z | |
| x >= y && x >= z = x | |
| y >= x && y >= z = y | |
| otherwise = z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment