X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fmaster-project%2Fc%CE%BBash.git;a=blobdiff_plain;f=HsValueMap.hs;h=f4498f20102a64d633859e2d06487c3963842ee1;hp=c2407f5ce7501600671a3cdf46a26250dab6dca0;hb=3f39038911a675d91b5147761e16296d3ab25743;hpb=41e6a89a1d9347431e80b895cb74ab5ecc03e9b7 diff --git a/HsValueMap.hs b/HsValueMap.hs index c2407f5..f4498f2 100644 --- a/HsValueMap.hs +++ b/HsValueMap.hs @@ -54,3 +54,19 @@ mkHsValueMap ty = else Single ty Nothing -> Single ty + +-- | Creates a map of pairs from two maps. The maps must have the same +-- structure. +zipValueMaps :: (Show a, Show b) => HsValueMap a -> HsValueMap b -> HsValueMap (a, b) +zipValueMaps = zipValueMapsWith (\a b -> (a, b)) + +-- | Creates a map of two maps using the given combination function. +zipValueMapsWith :: (Show a, Show b) => (a -> b -> c) -> HsValueMap a -> HsValueMap b -> HsValueMap c +zipValueMapsWith f (Tuple as) (Tuple bs) = + Tuple $ zipWith (zipValueMapsWith f) as bs +zipValueMapsWith f (Single a) (Single b) = + Single $ f a b +zipValueMapsWith _ a b = + --Tuple [] + error $ "Trying to zip unsimilarly formed trees!\n" ++ (show a) ++ "\nand\n" ++ (show b) +