X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=HsValueMap.hs;h=97e4cdb5d261f33c9f642e9b4c059f628a0ff5b5;hb=a3ea63eb2bd94867dae27a30aa900c9dfa9babb1;hp=c2407f5ce7501600671a3cdf46a26250dab6dca0;hpb=2ad58ca8b0552fc85e7c50b854f5673cf7f8156a;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git a/HsValueMap.hs b/HsValueMap.hs index c2407f5..97e4cdb 100644 --- a/HsValueMap.hs +++ b/HsValueMap.hs @@ -54,3 +54,18 @@ mkHsValueMap ty = else Single ty Nothing -> Single ty + +-- | Creates a map of pairs from two maps. The maps must have the same +-- structure. +zipValueMaps :: 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 :: (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 +zipValueMapWith _ _ _ = + error $ "Trying to zip unsimilarly formed trees!" +