this post was submitted on 04 Jun 2025
1025 points (98.8% liked)

Programmer Humor

23955 readers
1326 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
(page 2) 50 comments
sorted by: hot top controversial new old
[–] [email protected] 5 points 3 days ago

If you're consciously and intentionally using JavaScript like that, I don't want to be friends with you.

[–] [email protected] 11 points 4 days ago* (last edited 4 days ago) (1 children)

This is my favorite language: GHC Haskell

GHC Haskell:

GHCi> length (2, "foo")
1
[–] [email protected] 6 points 4 days ago (5 children)

Wait, now I need to know why.

* some time later *

I went to check why the hell this happened. It looks like the pair ("(,)") is defined as an instance of Foldable, for some reason, which is the class used by functions like foldl() and foldr(). Meanwhile, triples and other tuples of higher order (such as triples, quadruples, ...) are not instances of Foldable.

The weirdest part is that, if you try to use a pair as a Foldable, you only get the second value, for some reason... Here is an example.

ghci> foldl (\acc x -> x:acc) [] (1,2)

[2]

This makes it so that the returned length is 1.

[–] [email protected] 6 points 4 days ago

Oddly enough, in Haskell (as defined by the report), length is monomorphic, so it just doesn't work on tuples (type error).

Due to the way kinds (types of types) work in Haskell, Foldable instances can only operate over (i.e. length only counts) elements of the last/final type argument. So, for (,) it only counts the second part, which is always there exactly once. If you provided a Foldable for (,,,) it would also have length of 1.

load more comments (4 replies)
[–] [email protected] 4 points 3 days ago* (last edited 3 days ago) (5 children)

It's because + is two different operators and overloads based on the type to the left, while - is only a numeric operator and coerces left and right operands to numeric. But frankly if you're still using + for math or string concatenation in 2025, you're doing it wrong.

load more comments (5 replies)
[–] [email protected] 13 points 4 days ago

Feels like it could be one of those facebook posts to test "smart" people. Only the top 1% of people can answer this simple math question: "11" + 2 * 2 - 3

[–] [email protected] 2 points 3 days ago

It's my favorite language too, but I also find this hilarious.

load more comments
view more: ‹ prev next ›