290
functions (lemmy.nz)
submitted 9 months ago by cipherd@lemmy.ml to c/programmerhumor@lemmy.ml
you are viewing a single comment's thread
view the rest of the comments
[-] HiddenLayer555@lemmy.ml 1 points 9 months ago* (last edited 9 months ago)

I don't use any but I'm sure there are functional languages where () is a valid function.

[-] chaos@beehaw.org 5 points 9 months ago

In Haskell, that's "unit" or the empty tuple. It's basically an object with no contents, behavior, or particular meaning, useful for representing "nothing". It's a solid thing that is never a surprise, unlike undefined or other languages' nulls, which are holes in the language or errors waiting to happen.

You might argue that it's a value and not a function, but Haskell doesn't really differentiate the two anyway:

value :: String
value = "I'm always this string!"

funkyFunc :: String -> String
funkyFunc name = "Rock on, "++name++", rock on!"

Is value a value, or is it a function that takes no arguments? There's not really a difference, Haskell handles them both the same way: by lazily replacing anything matching the pattern on the left side of the equation with the right side of the equation at runtime.

[-] anton@lemmy.blahaj.zone 1 points 9 months ago

Mostly a great comment, but I wouldn't compare unit to null, it's more like the void type.

this post was submitted on 22 Nov 2025
290 points (99.0% liked)

Programmer Humor

43306 readers
2 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 7 years ago
MODERATORS