[Haskell-cafe] Variable-arity zipWith (re)invented.

adam vogt vogt.adam at gmail.com
Mon Dec 10 23:57:45 CET 2012


On Sat, Dec 8, 2012 at 10:27 AM, Takayuki Muranushi <muranushi at gmail.com> wrote:
> Continued discussion from
>
> https://groups.google.com/d/topic/haskell-cafe/-e-xaCEbd-w/discussion
> https://groups.google.com/d/topic/haskell-cafe/kM_-NvXAcx8/discussion
>
> Thank you for all the answeres and thinkings;
>
>
> Here's zipWithN for general Zip functors: [1] . This, together with
> [2] may constitute a small hackage. A modification from Wren's idea to
> [1] is the use of fmap instead of repeat.
>
> I'm wondering if there are any laws for Zip functors. I first thought
> that there are similarity between Zips and Applicatives, as [3] states
>
>>    instance Applicative f => Zip f where
>>        zip = liftA2 (,)
>
> However, my intuition is that zipping two arrays should result in an
> array of size of the same order as two, giving rise to a Zip functor
> law candidate:
>
> zipWith const xs $ zipWith const xs ys == zipWith const xs ys
>
> which is violated by the above statement "zip = liftA2 (,)" .
>
>
>
>
> [1] https://github.com/nushio3/practice/blob/master/variable-arity/ZipWithN-2.hs
> [2] https://github.com/nushio3/practice/blob/master/free-objects/zipf-12.hs
> [3] http://hackage.haskell.org/packages/archive/TypeCompose/0.9.7/doc/html/Data-Zip.html

Hi again, Takayuki

While the forZN in zipf-12 is able to infer the result type given
arguments, it doesn't give any useful information about types for
arguments unlike an example here:

http://code.haskell.org/~aavogt/flip_zipWithN/P4.hs

which imports a slight modification of Paczesiowa's code:
http://code.haskell.org/~aavogt/flip_zipWithN/Part1.lhs

But maybe it isn't possible to infer much about earlier arguments
given later ones since there is an instance   Zip ((->) a), that forZN
apparently can work with.

Adam



More information about the Haskell-Cafe mailing list