Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fucking Haskell and zips

Name: Anonymous 2011-04-23 14:08

So,

Haskell                          | Lisp
zip      l1 l2                   | (map list l1 l2)
zip3     l1 l2 l3                | (map list l1 l2 l3)
zip4     l1 l2 l3 l4             | (map list l1 l2 l3 l4)
zip5     l1 l2 l3 l4 l5          | (map list l1 l2 l3 l4 l5)
zip6     l1 l2 l3 l4 l5 l6       | (map list l1 l2 l3 l4 l5 l6)
zip7     l1 l2 l3 l4 l5 l6 l7    | (map list l1 l2 l3 l4 l5 l6 l7)
N/A                              | (map list . ls)
map      f  l                    | (map f l)
zipWith  f  l1 l2                | (map f l1 l2)
zipWith3 f  l1 l2 l3             | (map f l1 l2 l3)
zipWith4 f  l1 l2 l3 l4          | (map f l1 l2 l3 l4)
zipWith5 f  l1 l2 l3 l4 l5       | (map f l1 l2 l3 l4 l5)
zipWith6 f  l1 l2 l3 l4 l5 l6    | (map f l1 l2 l3 l4 l5 l6)
zipWith7 f  l1 l2 l3 l4 l5 l6 l7 | (map f l1 l2 l3 l4 l5 l7)
N/A                              | (map f . ls)


All this shit to achieve what Lisp does with ONE function? That is 6 lines of actual code in a naive implementation? Seriously?

(define map
 (case-lambda
  ((f xs)
   (do ((xs xs (cdr xs))
        (r '() (cons (f (car xs)) r)))
     ((null? xs) (reverse r))))
  ((f . xss)
   (do ((xss xss (map cdr xss))
        (r '() (cons (apply f (map car xss)) r)))
     ((ormap null? xs) (reverse r))))))

Name: Anonymous 2011-04-23 15:38

Actually...

lolmap :: [(a->b)] -> [a] -> [b]
lolmap _ [] = []
lolmap [] _ = []
lolmap (f:fs) (x:xs) = (f x):(lolmap fs xs)

someStupidFunction a b c d e = a+b+c+d+e

*Main> someStupidFunction `map` [1..5] `lolmap` [6..10] `lolmap` [11..15] `lolmap` [16..20] `lolmap` [21..25]
[55,60,65,70,75]


If you define some operators for this, it can also look pretty. I'm pretty sure that this is defined somewhere in Control.Applicative, but I'm not sure (I'm quite new to Haskell).

Also, if you look at zipWithN code, they are 4 lines max (two of which are type declaration which is not necessary). So no real code duplication there...

But since you can't have functions with variable number of arguments it's not that useful.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List