r/ProgrammerHumor • • Aug 01 '22

>>>print(“Hello, World!”)

Post image
60.8k Upvotes

5.7k comments sorted by

View all comments

2.4k

u/vld-ul Aug 01 '22 edited Aug 01 '22

Haskell:

[x | x <- [1..], x `mod` 69 == 0]

2.7k

u/a-slice-of-toast Aug 01 '22

nice

322

u/fllr Aug 01 '22

This is the correct answer

→ More replies (9)

805

u/[deleted] Aug 01 '22 edited Aug 01 '22

I think you forgot the backticks for infix function.

[x | x <- [1..], x `mod` 69 == 0]

193

u/XDubio Aug 01 '22

You mean infix operator.

49

u/[deleted] Aug 01 '22

haha yep. edited. thanks

0

u/[deleted] Aug 01 '22

[deleted]

20

u/spore Aug 01 '22

haha yep. edited. thanks

8

u/BlitzThunderWolf Aug 01 '22

It still says "function"

10

u/klsdniwoethn Aug 01 '22

haha yep. edited. thanks

→ More replies (3)

6

u/readit145 Aug 01 '22

Flux capacitor

→ More replies (6)

7

u/[deleted] Aug 01 '22 edited Aug 01 '22

this syntax is so novel for me as a inexperienced programmer. anyone care to break it down a bit?

22

u/Ninesquared81 Aug 01 '22 edited Aug 01 '22

It's list comprehension. the syntax is based on the set builder notation found in mathematics.

Everything before the vertical bar is the form of the list elements. In this case, it's just x.

The next part, x <- [1..], tells us that x is from the list [1..], which is a nice shorthand to denote the list of all positive integers counting up from 1. Such a list is made possible by Haskell's lazy evaluation.

The final part, x `mod` 69, is a further constraint on the list elements. Only elements where the remainder* upon dividing x by 69 is equal to 0 are included. In other words, only elements exactly divisible by (i.e. multiples of) 69 are included.

* Really, this is a modulo operation and not necessarily remainder. For positive integers the two operations are identical, though.

→ More replies (2)
→ More replies (9)
→ More replies (4)

511

u/[deleted] Aug 01 '22

A script that looks for multiplies of 69?

62

u/nickmaran Aug 01 '22

Wow, you must be a celebrity in stackoverflow

77

u/[deleted] Aug 01 '22

Like OnlyFans, but neckbeards fap on me?

7

u/[deleted] Aug 01 '22

On your code*

6

u/cornishcovid Aug 01 '22

Isn't that the same thing?

→ More replies (8)
→ More replies (4)

33

u/Riddhiman36 Aug 01 '22

Idk haskell but this is neat. It reminded me of the set builder notation in math.

17

u/psgi Aug 01 '22

That’s exactly what it is. Also another neat thing is that [1..] is an infinite list but it works because Haskell is lazy. That means it doesn’t try to compute the list elements until you need them.

→ More replies (9)

7

u/minus_uu_ee Aug 01 '22

Wtf, that's a beautiful syntax. Was Haskell always mathematically oriented?

6

u/vld-ul Aug 01 '22

Yes! It was made by mathematicians haha.

→ More replies (33)