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

The joke that is Haskell stdlib

Name: TRUE TRUTH EXPERT 2010-05-17 5:19

oBSERVE MY GOOD OL' FELLAS, THE JOKE THAT IS 'HASKELL STDLIB'. i DO NOT DOUBT THE EXCELLENCE IN HASKELL THEORY, BUT ALLOW ME TO MAKE FUN OF THE FRIVOLOUS LIBRARY THEY HAVE FOR STANDARD. LA-FUCKING-OWL.


-- | 'zip' takes two lists and returns a list of corresponding pairs.
-- If one input list is short, excess elements of the longer list are
-- discarded.
zip :: [a] -> [b] -> [(a,b)]
zip (a:as) (b:bs) = (a,b) : zip as bs
zip _      _      = []

;; I shall compare it with Communist Lisp
;; notice the solution is more general
;; and the documentation is built-in
(defun zip (&rest lists)
  "zip takes lists and returns corresponding pairs"
  (apply #'mapcar #'list lists))


o GUESS WAT! BAAA!!! hASKELL PROVIDES zip3 HOHOHOH. wAT ABOUT ZIP4 YOU ASSHOLES??

wAIT, WAIT. nOW IT GETS BETTER.


-- | 'unzip' transforms a list of pairs into a list of first components
-- and a list of second components.
unzip    :: [(a,b)] -> ([a],[b])
{-# INLINE unzip #-}
unzip    =  foldr (\(a,b) ~(as,bs) -> (a:as,b:bs)) ([],[])


;; La Communa lispa
(defun unzip (&rest lists)
  "list of pairs -> list of components"
  (apply #'zip lists))

oH SHIT!!!! fULL GENERAL SOLUTION WITH THE POWAH OF LISPA, HA SS KELL STDLIB IS A JOKE. dID YOU FUCKING LOL READING THIS POST?

Name: Anonymous 2010-05-17 5:27

your lisp functions aren't type-safe.

Name: Anonymous 2010-05-17 5:32

>>2

oH I'M SORRY, LET ME USE DEFMETHOD INSTEAD.

Name: Anonymous 2010-05-17 5:41

>>1
It's not really a fair comparison between Haskell and Lisp as Haskells solution is the best afforded by the type system, whereas Lisp is dynamically typed and free to ignore everything except the pair structure.

As an aside,
Scheme's SRFI 1 fails by having unzip1, unzip2, unzip3, unzip4 and unzip5. This is because unzip[1-5] return multiple vales rather than a list.
You can still do the fully generalized unzip, but you would need to write that utility yourself [snarky-comment]as difficult as that is[/snarky-comment]

Name: Anonymous 2010-05-17 5:57

why are you using zip instead of transpose?

Name: 4 2010-05-17 5:59

>>1
Also, you have a bug in your unzip, lists shouldn't be a &rest argument, but a normal one.

food for thought
do we think this is right?
* (unzip '((a b c) (d e) (f g h)))

((A D F) (B E G))
*
I understand why it does this (if mapcar takes multiple lists, it stops on the shortest one), but this is one of the issues that Haskell avoids by being an anal retentive bitch.

Name: Anonymous 2010-05-17 6:07

>>6
Also, you have a bug in your unzip, lists shouldn't be a &rest argument, but a normal one.
care to elaborate? it works fine here. I tested. Quite a brilliant implementation too. I like how he made UNZIP look like a useless function to have, by having ZIP being the inverse of itself.

Name: Anonymous 2010-05-17 6:08

>>8
Well, if you want (unzip (zip x)) to be x... He's right about &rest.

Name: Anonymous 2010-05-17 6:10

>>4
wasn't that the reason haskellers advocated haskell? now they say things aren't 'fair'? is the type system a plus or something that isn't 'fair'?

Name: Anonymous 2010-05-17 6:11

>>8
Exactly my point. I didn't see the point in having zip return a list, if unzip didn't accept a list.

Name: Anonymous 2010-05-17 6:13

>>9
I'm not a Haskeller, I'm a Schemer. I still maintain that it isn't right to compare statically typed and dynamically typed languages on type issues, as they have fundamentally different notions of what a type is.

Name: Anonymous 2010-05-17 6:28

>>9
>>4 is a lisper who doesn't realize that the type system is a plus.

also, transpose probably is what you want, unless you really want to use lists of different types.

Name: Anonymous 2010-05-17 6:45

>>12
2 points.
1. I'm a lisper? Wow, did you figure that out from the part where I fucking came out and said it
2. I never said the type system wasn't a plus, I said that you shouldn't compare Haskell's and Lisp's type systems, as they aren't really comparable.

Name: Anonymous 2010-05-17 6:47

Guys, your inferior type systems are laughable.
TROLLGOL has user-defined type settings and you can change type systems as the program is running.

Name: Anonymous 2010-05-17 7:11

So basically, what haskellers are saying is that you can't implement a general zip in haskell.

Name: Anonymous 2010-05-17 7:33

>>15
that's true, but it's also true you will never need a zip4+ in your entire life.

Name: Anonymous 2010-05-17 7:35

>>16
"but look how elegantly qsort is implemented!!!"

Name: Anonymous 2010-05-17 8:07

>>15
transpose

Name: Anonymous 2010-05-17 8:16

>>18
transpose [[1, 2, 3], "abc"]. threadover.

Name: Anonymous 2010-05-17 8:19

>>19
$ ghci
GHCi, version 6.10.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude> import Data.List
Prelude Data.List> transpose [[1,2,3],"abc"]

<interactive>:1:16:
    No instance for (Num Char)
      arising from the literal `3' at <interactive>:1:16
    Possible fix: add an instance declaration for (Num Char)
    In the expression: 3
    In the expression: [1, 2, 3]
    In the first argument of `transpose', namely `[[1, 2, 3], "abc"]'
Prelude Data.List> :t transpose
transpose :: [[a]] -> [[a]]

Name: Anonymous 2010-05-17 8:29

>>20
Prelude Data.List Data.Char> transpose [[1,2,3], map ord "abc"]
[[1,97],[2,98],[3,99]]
Prelude Data.List Data.Char> transpose [map chr [1,2,3], "abc"]
["\SOHa","\STXb","\ETXc"]
Prelude Data.List Data.Char>


but why the fuck would you want to do that?

Name: Anonymous 2010-05-17 8:38

>>20-21
alternatively, add an instance declaration for (Num Char).

Name: Anonymous 2010-05-17 8:50

This thread is bullshit.

Name: Anonymous 2010-05-17 9:23

I'd rather write my own zip[n] than have bugs that a decent type system could have caught.

Name: Anonymous 2010-05-17 9:27

>>24
Why is your compiler smarter than you are? Is it because your compiler is very smart?

Name: Anonymous 2010-05-17 9:52

>>25
My compiler is smart so I don't have to be. Have fun hunting down bugs that my compiler found instantly.

Name: Anonymous 2010-05-17 10:38

>>25
183kb of pure lean code

Name: Anonymous 2010-05-17 10:52

>>27
You compiler may be bigger than mine but mine's smarter and quicker. 182kb of pure lean code.

Name: Anonymous 2010-05-17 11:07

>>26
I will, along with my being smarter than you and your compiler.

Name: Anonymous 2010-05-17 12:15

The joke I think is that the CL implementation is clearly superior and a one liner.

Name: Anonymous 2010-05-17 12:31

About Ord:

(Ord  a, Ord  b, Ord  c) => Ord  (a, b, c)
(Ord a, Ord b, Ord c, Ord d) => Ord (a, b, c, d)
(Ord a, Ord b, Ord c, Ord d, Ord e) => Ord (a, b, c, d, e)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f) => Ord (a, b, c, d, e, f)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g) => Ord (a, b, c, d, e, f, g)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h) => Ord (a, b, c, d, e, f, g, h)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i) => Ord (a, b, c, d, e, f, g, h, i)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j) => Ord (a, b, c, d, e, f, g, h, i, j)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k) => Ord (a, b, c, d, e, f, g, h, i, j, k)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l) => Ord (a, b, c, d, e, f, g, h, i, j, k, l)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
(Ord a, Ord b, Ord c, Ord d, Ord e, Ord f, Ord g, Ord h, Ord i, Ord j, Ord k, Ord l, Ord m, Ord n, Ord o) => Ord (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)

lold heartily.

Name: Anonymous 2010-05-17 12:59

>>1
Your zip and the Haskell zip don't do the same thing. Haskell's zip takes two lists and returns a list of pairs. Your zip takes any number of lists and returns a list of lists.

Haskell's unzip takes a list of pairs and returns a pair of lists. Your unzip takes a list of lists and returns a list of lists.

The inverse of Haskell's unzip is uncurry zip.

Name: Anonymous 2010-05-17 13:07

>>32
You've clearly never used a three-way zip. The Haskell version is wrong

Name: Anonymous 2010-05-17 13:08

Your zip and the Haskell zip don't do the same thing. Haskell's zip takes two lists and returns a list of pairs. Your zip takes any number of lists and returns a list of lists.
Haskell's unzip takes a list of pairs and returns a pair of lists. Your unzip takes a list of lists and returns a list of lists.


That's idiotic. In lisp, a pair is a CONS, but you can also represent it with (a b). so what?

Name: Anonymous 2010-05-17 13:26

>>32
splitting hairs over a pointer to '() is pretty lame, dude.

Name: Anonymous 2010-05-17 13:29

``That's what I'll do!; I'll go on /prog/ and complain about it!''

Name: Anonymous 2010-05-17 13:38

One word: import Network


CAN'T DO THAT ON YOUR FUCKING TWELVE IMPLEMENTATIONS AND 30 BROKEN UNDOCUMENTED SOCKET LIBRARIES, CAN YOU, LISP WEENY?

Name: Anonymous 2010-05-17 13:48

>>37
start a different thread, we're complaining about Haskell right now.

Name: Anonymous 2010-05-17 13:53

>>37
You really need to ask yourself "Do lisp programmers need networking?" How does Haskell cope with errors? How do you design your programs? Or do you write your own error system?

Name: Anonymous 2010-05-17 14:03

>>37
(require :trivial-sockets)

Works like a charm.

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