Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
data Ragged a = Ragged (Either a [Ragged a]) deriving (Show) zip' :: Ragged a -> Ragged b -> Ragged (a, b) zip' (Ragged x) (Ragged y) = Ragged $ go x y where go :: Either a [Ragged a] -> Either b [Ragged b] -> Either (a,b) [Ragged (a,b)] go (Left x) (Left y) = Left (x, y) go (Left x) (Right ys) = Right $ (zip' $ Ragged $ Left x) <$> ys go (Right xs) (Left y) = Right $ (flip zip' $ Ragged $ Left y) <$> xs go (Right xs) (Right ys) = Right $ zipWith zip' xs ys
data Ragged a = Ragged (Either a [Ragged a]) deriving (Show) zip' :: Ragged a -> Ragged b -> Ragged (a, b) zip' (Ragged x) (Ragged y) = Ragged $ go x y where go :: Either a [Ragged a] -> Either b [Ragged b] -> Either (a,b) [Ragged (a,b)] go (Left x) (Left y) = Left (x, y) go (Left x) (Right ys) = Right $ (zip' $ Ragged $ Left x) <$> ys go (Right xs) (Left y) = Right $ (flip zip' $ Ragged $ Left y) <$> xs go (Right xs) (Right ys) = Right $ zipWith zip' xs ys
data Ragged a = Ragged (Either a [Ragged a]) zip' :: Ragged a -> Ragged b -> Ragged (a, b) zip' (Ragged x) (Ragged y) = Ragged $ go x y where go :: Either a [Ragged a] -> Either b [Ragged b] -> Either (a,b) [Ragged (a,b)] go (Left x) (Left y) = Left (x, y) go (Left x) (Right ys) = Right $ (zip' $ Ragged $ Left x) <$> ys go (Right xs) (Left y) = Right $ (flip zip' $ Ragged $ Left y) <$> xs go (Right xs) (Right ys) = Right $ zipWith zip' xs ys
zip 1[1][2[[2,3,[5,4]]4]]] = [[[(1,2),(1,3),[(1,5),(1,4)]]]]] zip [1,2] [3,[4,5]] = [(1,3),[(2,4),(2,5)]] zip [[2,3],4] [1,[6,7]] = [[(2,1),(3,1)],[(4,6),(4,7)]]
zip 1[2,3,[5,4]] = [(1,2),(1,3),[(1,5),(1,4)]] zip [1,2] [3,[4,5]] = [(1,3),[(2,4),(2,5)]] zip [[2,3],4] [1,[6,7]] = [[(2,1),(3,1)],[(4,6),(4,7)]]
zip [1][[2,3,[5,4]]] = [[(1,2),(1,3),[(1,5),(1,4)]]] zip [1,2] [3,[4,5]] = [(1,3),[(2,4),(2,5)]] zip [[2,3],4] [1,[6,7]] = [[(2,1),(3,1)],[(4,6),(4,7)]]