I was needing a way to zip generic data structures together today and was very annoyed to find that there is no Zippable class, or variant there of.<br><br>So I made my own:<br><br>class (Foldable f, Functor f) =&gt; Zippable f where<br>
  fmaps :: (Foldable g) =&gt; g (a -&gt; b) -&gt; f a -&gt; f b<br>  fmaps&#39; :: [a -&gt; b] -&gt; f a -&gt; f b -- to save a step on instance implementation<br>  zipWith :: (a -&gt; b -&gt; c) -&gt; f a -&gt; f b -&gt; f c<br>
  zip ::  f a -&gt; f b -&gt; f (a, b)<br>  unzip :: f (a, b) -&gt; (f a, f b)<br>  <br>  fmaps fs a = fmaps&#39; (toList fs) a<br>  fmaps&#39; fs a = fmaps fs a<br>  zipWith f a b = fmaps (fmap f a) b<br>  zip = zipWith (,)<br>
  unzip a = (fmap fst a, fmap snd a) <br>  <br>instance Zippable [] where<br>  fmaps&#39; (fx:fs) (x:xs) = fx x : fmaps&#39; fs xs<br>  fmaps&#39; _       _      = []<br>  <br>--The fmaps function is also quite handy as a replacment for zipWith3, zipWith4, etc...<br>
--For example:<br>  <br>x = [1, 3, 5, 7, 3]<br>y = [6, 9, 3, 1, 4]<br>z = [2, 4, 0, 8, 2]<br>test = fmap (,,) x `fmaps` y `fmaps` z<br>-- &gt; [(1,6,2),(3,9,4),(5,3,0),(7,1,8),(3,4,2)]<br><br>--you can also throw in a functor instance to remove the dependency on the Functor class, but it <br>
--  might not be worth it:<br>instance (Zippable f) =&gt; Functor f where<br>  fmap f a = fmaps (repeat f) a<br><br><br>Is there any good reason that there isn&#39;t something like this in the standard libraries? Or, as far as I can tell, on hackage?<br>
If not, then maybe I&#39;ll stick it on hackage.<br><br>- Job Vranish<br><br><br>