-
-
Save sshine/8f350c862a1e49a1e7a3e1fca5bd12b6 to your computer and use it in GitHub Desktop.
This file contains 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
src/MinimalProjectGroups.hs:27:25: error: | |
• Couldn't match type ‘skill1’ with ‘skill’ | |
‘skill1’ is a rigid type variable bound by | |
the type signature for: | |
skillsOf :: forall skill1. | |
(Ord employee, Ord skill1) => | |
employee -> Set skill1 | |
at src/MinimalProjectGroups.hs:26:5-66 | |
‘skill’ is a rigid type variable bound by | |
the type signature for: | |
minimalGroups :: forall employee skill. | |
(Ord employee, Ord skill) => | |
Map employee (Set skill) -> Set skill -> Set (Set employee) | |
at src/MinimalProjectGroups.hs:(13,1)-(15,64) | |
Expected type: Set skill1 | |
Actual type: Set skill | |
• In the expression: Map.findWithDefault Set.empty employee staff | |
In an equation for ‘skillsOf’: | |
skillsOf employee = Map.findWithDefault Set.empty employee staff | |
In an equation for ‘minimalGroups’: | |
minimalGroups staff requirements | |
= Set.filter | |
(\ group -> isSufficient group && isMinimal group) allGroups | |
where | |
allGroups :: Ord employee => Set (Set employee) | |
allGroups = Set.powerSet (Map.keysSet staff) | |
isSufficient :: Ord employee => Set employee -> Bool | |
isSufficient group | |
= requirements `Set.isSubsetOf` Set.unions (Set.map skillsOf group) | |
.... | |
• Relevant bindings include | |
skillsOf :: employee -> Set skill1 | |
(bound at src/MinimalProjectGroups.hs:27:5) | |
requirements :: Set skill | |
(bound at src/MinimalProjectGroups.hs:16:21) | |
staff :: Map employee (Set skill) | |
(bound at src/MinimalProjectGroups.hs:16:15) | |
minimalGroups :: Map employee (Set skill) | |
-> Set skill -> Set (Set employee) | |
(bound at src/MinimalProjectGroups.hs:16:1) | |
| | |
27 | skillsOf employee = Map.findWithDefault Set.empty employee staff | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
This file contains 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
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
module MinimalProjectGroups where | |
import Data.Map.Strict (Map) | |
import qualified Data.Map.Strict as Map | |
import Data.Set (Set) | |
import qualified Data.Set as Set | |
import Data.Text (Text) | |
import qualified Data.Text as Text | |
minimalGroups | |
:: forall employee. forall skill. (Ord employee, Ord skill) | |
=> Map employee (Set skill) -> Set skill -> Set (Set employee) | |
minimalGroups staff requirements = | |
Set.filter (\group -> isSufficient group && isMinimal group) allGroups | |
where | |
allGroups :: Ord employee => Set (Set employee) | |
allGroups = Set.powerSet (Map.keysSet staff) | |
isSufficient :: Ord employee => Set employee -> Bool | |
isSufficient group = | |
requirements `Set.isSubsetOf` Set.unions (Set.map skillsOf group) | |
skillsOf :: (Ord employee, Ord skill) => employee -> Set skill | |
skillsOf employee = Map.findWithDefault Set.empty employee staff | |
isMinimal :: Ord employee => Set employee -> Bool | |
isMinimal group = all (`isEssentialFor` group) group | |
isEssentialFor :: Ord employee => employee -> Set employee -> Bool | |
isEssentialFor employee group = | |
not (isSufficient (Set.delete employee group)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment