Symmetry Symmetry

I was implementing the [un]zip family of functions (from Haskel, see List functions) and noticed this lovely symmetry: unzip(unzip(a)) –> a

One element lists:
listUnzip(L(L(1,2,3,4,5,6,7,8,9,0))) –> L(L(1),L(2),L(3),L(4),L(5),L(6),L(7),L(8),L(9),L(0))
listUnzip(L(L(1),L(2),L(3),L(4),L(5),L(6),L(7),L(8),L(9),L(0))) –> L(L(1,2,3,4,5,6,7,8,9,0))

listUnzip(L( L(1,2), L(3,4), L(5,6), L(7,8), L(9,0))) –> L( L(1,3,5,7,9), L(2,4,6,8,0))
listUnzip(L( L(1,3,5,7,9), L(2,4,6,8,0))) –> L( L(1,2), L(3,4), L(5,6), L(7,8), L(9,0))

listUnzip(L( L(1,2,3), L(4,5,6), L(7,8,9))) –> L( L(1,4,7), L(2,5,8), L(3,6,9))
listUnzip(L( L(1,4,7), L(2,5,8), L(3,6,9))) –> L( L(1,2,3), L(4,5,6), L(7,8,9))

listUnzip(L( L(1,2,3,4), L(5,6,7,8))) –> L( L(1,5), L(2,6), L(3,7), L(4,8))
listUnzip(L( L(1,5), L(2,6), L(3,7), L(4,8))) –> L( L(1,2,3,4), L(5,6,7,8))

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s