Created
July 7, 2011 00:50
-
-
Save rhz/1068694 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
import qualified Data.Map as Map | |
import qualified Data.Set as Set | |
type IntMap = Map.Map Int Int | |
type IntSet = Set.Set Int | |
extend :: IntMap -> IntSet -> IntMap -> Maybe (IntMap, IntSet) | |
extend inj codom map = Map.foldrWithKey f (Just (inj, codom)) map | |
where f :: Int -> Int -> Maybe (IntMap, IntSet) -> Maybe (IntMap, IntSet) | |
f i j (Just (inj, codom)) = if Set.member j codom | |
then Nothing | |
else Just ((Map.insert i j inj), (Set.insert j codom)) | |
f _ _ _ = Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment