From: Florian Frank Date: 2002-11-19T23:40:10+09:00 Subject: Re: ruby-dev summary 18613-18710 On 2002-11-17 19:16:30 +0900, Massimiliano Mirra wrote: > That's because you happen to have numeric keys. Try with {:one => > 'two', :three => 'four'}. I did, and there's no difference. yield is called with the arguments [key, value], so the result of {:one => 'two', :three => 'four'}.zip is equivalent to [[:one, 'two'], [:three, 'four']].zip . > > In Haskell its only possible to zip two or three "lists" with the > > standard library functions. > (Just curious: why?) In Prelude.hs the following zip functions are defined: zip :: [a] -> [b] -> [(a,b)] zip = zipWith (\a b -> (a,b)) zip3 :: [a] -> [b] -> [c] -> [(a,b,c)] zip3 = zipWith3 (\a b c -> (a,b,c)) zipWith :: (a->b->c) -> [a]->[b]->[c] zipWith z (a:as) (b:bs) = z a b : zipWith z as bs zipWith _ _ _ = [] zipWith3 :: (a->b->c->d) -> [a]->[b]->[c]->[d] zipWith3 z (a:as) (b:bs) (c:cs) = z a b c : zipWith3 z as bs cs zipWith3 _ _ _ _ = [] In List.hs zip4, zip5, etc. are defined in a similar fashion. In Haskell it doesn't seem to be possible to use arbitrary length argument lists in functions because every function has a finite function signature, the type sequence after the "::". Perhaps it would be possible to define a function that has got a domain of [[a]]. The best I could come up with is that: myZip :: [[a]] -> [[a]] myZip [] = [] myZip args = iter 0 args where iter i l | i < length l = row i l : iter (i + 1) l | otherwise = [] row i xs = map (\x -> x !! i) xs Now there remains the problem to build tuples from the lists of the codomain, but tuples have to be of a finite type again. To program a myZipWith a apply function for lists is required, but that seems to be difficult because of similiar reasons. Perhaps there are people that learned more of the LOTY on this mailinglist who know how to do this if possible? BTW: This year isn't over yet... ;) > > You can't shock me -- I confess: I'm a perl programmer. *g* > LOL Well, confession heard, my son, now you can repent... (just > kidding) And I haven't even confessed yet that I started programming with BASIC. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth, "A memo to Peter van Emde Boas"