Skip to content

Instantly share code, notes, and snippets.



Created Jul 7, 2011
What would you like to do?
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
You can’t perform that action at this time.