Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
The Zip class from Data.Zip requires an implementation of Semialign: class Semialign f => Zip f In my mind: Zip takes the intersection of two shapes. Semialign takes the union of two sha...
Question
haskell
#2: Post edited
Why does `Zip` require `SemiAlign`
- Why does `Zip` require `Semialign`
The `Zip` class from `Data.Zip` requires an implementation of `SemiAlign`:- ```haskell
class SemiAlign f => Zip f- ```
- In my mind:
- - `Zip` takes the intersection of two shapes.
- `SemiAlign` takes the union of two shapes.- For 2D matrices I can take the intersection of two matrices, but not the union. For example:
- ```
- a :: Array (Int, Int) Int
- a =
- matrix
- [[1,1,1]
- ,[1,1,1]
- ]
- b :: Array (Int, Int) Int
- b =
- matrix
- [[0,2]
- ,[2,0]
- ,[0,2]
- ]
- ```
- I can zip these:
- ```text
- zipWith (+) a b =
- [[1,3]
- ,[3,1]
- ]
- ```
- but their union is not a rectangle, so I can't align them.
But implementing `Zip` on `Array (Int, Int)`, requires first implementing `SemiAlign`.- Why is that? It seems like a totally extraneous requirement.
- The `Zip` class from `Data.Zip` requires an implementation of `Semialign`:
- ```haskell
- class Semialign f => Zip f
- ```
- In my mind:
- - `Zip` takes the intersection of two shapes.
- - `Semialign` takes the union of two shapes.
- For 2D matrices I can take the intersection of two matrices, but not the union. For example:
- ```
- a :: Array (Int, Int) Int
- a =
- matrix
- [[1,1,1]
- ,[1,1,1]
- ]
- b :: Array (Int, Int) Int
- b =
- matrix
- [[0,2]
- ,[2,0]
- ,[0,2]
- ]
- ```
- I can zip these:
- ```text
- zipWith (+) a b =
- [[1,3]
- ,[3,1]
- ]
- ```
- but their union is not a rectangle, so I can't align them.
- But implementing `Zip` on `Array (Int, Int)`, requires first implementing `Semialign`.
- Why is that? It seems like a totally extraneous requirement.
#1: Initial revision
Why does `Zip` require `SemiAlign`
The `Zip` class from `Data.Zip` requires an implementation of `SemiAlign`: ```haskell class SemiAlign f => Zip f ``` In my mind: - `Zip` takes the intersection of two shapes. - `SemiAlign` takes the union of two shapes. For 2D matrices I can take the intersection of two matrices, but not the union. For example: ``` a :: Array (Int, Int) Int a = matrix [[1,1,1] ,[1,1,1] ] b :: Array (Int, Int) Int b = matrix [[0,2] ,[2,0] ,[0,2] ] ``` I can zip these: ```text zipWith (+) a b = [[1,3] ,[3,1] ] ``` but their union is not a rectangle, so I can't align them. But implementing `Zip` on `Array (Int, Int)`, requires first implementing `SemiAlign`. Why is that? It seems like a totally extraneous requirement.