Using a custom data type is usually the best option, but if you really want to use tuples, you can start by defining a comparingFst helper function that compares based on the first element of the tuple.
import Data.Ord import Data.List -- Dummy data types for example purposes. Derive from Show just so -- that the example can be more easily tested interactively in ghci. data Aa = Aa deriving Show data Cc = Cc deriving Show type Something = (Float, Float, Int, Aa, Cc, Int) comparingFst :: Something -> Something -> Ordering comparingFst = comparing fstSomething where fstSomething (x,_,_,_,_,_) = x
Now you can take the smaller of the two elements with:
findMin :: Something -> Something -> Something findMin xy = case comparingFst xy of LT -> x _ -> y
or from the list of items
findMinimum :: [Something] -> Something findMinimum = minimumBy comparingFst
And you can also use the same helper function to sort:
sortSomethings :: [Something] -> [Something] sortSomethings = sortBy comparingFst
In addition, it is worth mentioning that, by default, tuples are compared by elements, starting from the first element, so if your types Aa and Bb can be obtained from Ord and Eq , you do not need anything extra, i.e. an example becomes:
import Data.List data Ab = Ab deriving (Show, Ord, Eq) data Cc = Cc deriving (Show, Ord, Eq) type Something = (Float, Float, Int, Ab, Cc, Int) findMin :: Something -> Something -> Something findMin xy = min xy findMinimum :: [Something] -> Something findMinimum = minimum sortSomethings :: [Something] -> [Something] sortSomethings = sort
In other words, you can just use the standard min and sort as-is functions.