merge :: V.Vector Env -> Env -- Types Env and unified env
-- this should be easier...
merge envs = go Map.empty $ envsToMaps envs
    where
        -- only Left if there is a name/type-clash... TODO
        go acc maps
            | V.null maps = Env acc
            | otherwise =
                let map = V.head maps
                in go (merge2 acc map) $ V.tail maps
        merge2 acc entToModeMap
            | length (Map.keys entToModeMap) == 1 -- since every line in the CSV file is turned into an Env
                = let key = head $ Map.keys entToModeMap
                  in case acc ^.at key of -- is current entity elem of final env?
                        Nothing -> acc & at key ?~ (fromJust $ entToModeMap ^.at key)
                        Just acc' -> let modeMap = updateModeMap acc' $ fromJust $ entToModeMap ^.at key
                                     in acc & at key ?~ modeMap
            | otherwise = error "merge2"
merge :: V.Vector Env -> Env
merge envs = go Map.empty $ envsToMaps envs
    where
        -- only Left if there is a name/type-clash... TODO
        go acc maps
            | V.null maps = Env acc
            | otherwise =
                let map = V.head maps
                in go (merge2 acc map) $ V.tail maps
        merge2 acc entToModeMap
            | length (Map.keys entToModeMap) == 1 -- since every line in the CSV file is turned into an Env
                = let key = head $ Map.keys entToModeMap
                  in case acc ^.at key of -- is current entity elem of final env?
                        Nothing -> acc & at key ?~ (fromJust $ entToModeMap ^.at key)
                        Just acc' -> let modeMap = updateModeMap acc' $ fromJust $ entToModeMap ^.at key
                                     in acc & at key ?~ modeMap
            | otherwise = error "merge2"
merge envs = go Map.empty $ envsToMaps envs
    where
        -- only Left if there is a name/type-clash... TODO
        go acc maps
            | V.null maps = Env acc
            | otherwise =
                let map = V.head maps
                in go (merge2 acc map) $ V.tail maps
        merge2 acc entToModeMap
            | length (Map.keys entToModeMap) == 1 -- since every line in the CSV file is turned into an Env
                = let key = head $ Map.keys entToModeMap
                  in case acc ^.at key of -- is current entity elem of final env?
                        Nothing -> acc & at key ?~ (fromJust $ entToModeMap ^.at key)
                        Just acc' -> let modeMap = updateModeMap acc' $ fromJust $ entToModeMap ^.at key
                                     in acc & at key ?~ modeMap
            | otherwise = error "merge2"