Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created April 13, 2012 05:16
Show Gist options
  • Save tonymorris/2373889 to your computer and use it in GitHub Desktop.
Save tonymorris/2373889 to your computer and use it in GitHub Desktop.
Ugly -> nicer?
class Functor f => Unzip f where
unfzip ::
f (a, b)
-> (f a, f b)
unfzip3 ::
f (a, b, c)
-> (f a, f b, f c)
unfzip3 x =
let (a, bc) = unfzip (fmap (\(a', b', c') -> (a', (b', c'))) x)
(b, c) = unfzip bc
in (a, b, c)
unfzip4 ::
f (a, b, c, d)
-> (f a, f b, f c, f d)
unfzip4 x =
let (a, b, cd) = unfzip3 (fmap (\(a', b', c', d') -> (a', b', (c', d'))) x)
(c, d) = unfzip cd
in (a, b, c, d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment