getInstalledTool :: [PackageIdentifier] -- ^ already installed
                 -> PackageName         -- ^ package to find
                 -> (Version -> Bool)   -- ^ which versions are acceptable
                 -> Maybe PackageIdentifier
getInstalledTool installed name goodVersion =
    if null available
        then Nothing
        else Just $ maximumBy (comparing packageIdentifierVersion) available
  where
    available = filter goodPackage installed
    goodPackage pi' =
        packageIdentifierName pi' == name &&
        goodVersion (packageIdentifierVersion pi')
getInstalledTool :: [PackageIdentifier] -- ^ already installed
                 -> PackageName         -- ^ package to find
                 -> (Version -> Bool)   -- ^ which versions are acceptable
                 -> Maybe PackageIdentifier
getInstalledTool installed name goodVersion =
    if null available
        then Nothing
        else Just $ maximumBy (comparing packageIdentifierVersion) available
  where
    available = filter goodPackage installed
    goodPackage pi' =
        packageIdentifierName pi' == name &&
        goodVersion (packageIdentifierVersion pi')
getInstalledTool installed name goodVersion =
    if null available
        then Nothing
        else Just $ maximumBy (comparing packageIdentifierVersion) available
  where
    available = filter goodPackage installed
    goodPackage pi' =
        packageIdentifierName pi' == name &&
        goodVersion (packageIdentifierVersion pi')