326
submitted 2 days ago* (last edited 2 days ago) by HiddenLayer555@lemmy.ml to c/programmer_humor@programming.dev

Made with KolourPaint and screenshots from Kate (with the GitHub theme).

you are viewing a single comment's thread
view the rest of the comments
[-] barsoap@lemm.ee 26 points 2 days ago* (last edited 2 days ago)

The actual reason why let ... in syntax tends to not use C-style "type var" like syntax is because it's derived from the syntax type theory uses, and type theorists know about parameterised types. Generics, in C++ parlance, excuse my Haskell:

let foo :: Map Int String = mempty

We have an empty map, and it maps integers to Strings. We call it foo. Compare:

Map Int String foo = mempty

If nothing else, that's just awkward to read and while it may be grammatically unambiguous (a token is a name if it sits directly in front of =) parser error messages are going to suck. Map<Int,String> is also awkward but alas that's what we're stuck with in Rust because they reasoned that it would be cruel to put folks coming from C++ on angle bracket withdrawal. Also Rust has ML ancestry don't get me started on their type syntax.

[-] HiddenLayer555@lemmy.ml 2 points 1 day ago* (last edited 1 day ago)

How do you do nested parameterized types without it becoming ambiguous though? That's IMO the biggest advantage of the bracket syntax. For example: Map<Tuple<Int, Int, Int> Int>

[-] barsoap@lemm.ee 4 points 1 day ago

Map (Int, Int) Int. Kind of a bad example because tuples have special-case infix syntax, the general case would be Map Int (Either Int Bool). Follows the same exact syntax as function application just that types (by enforced convention) start upper case. Modulo technical wibbles to ensure that type inference is possible you can consider type constructors to be functions from types to types.

...function application syntax is a story in itself in Haskell because foo a b c gets desugared to (((foo a) b) c): There's only one-argument functions. If you want to have more arguments, accept an argument and return a function that accepts yet another argument. Then hide all that under syntactic sugar so that it looks innocent. And, of course, optimise it away when compiling. Thus you can write stuff like map (+5) xs in Haskell while other languages need the equivalent of map (\x -> x + 5) xs (imagine the \ is a lambda symbol).

[-] HiddenLayer555@lemmy.ml 2 points 1 day ago* (last edited 1 day ago)

Interesting. Thanks!

[-] weird@sub.wetshaving.social 7 points 2 days ago

There is also the thing where the compiler might mistake your c++ style variable declaration for a function, e.g.

String myfunction():

String myvariable();

[-] ulterno@programming.dev 0 points 1 day ago

Until now, I looked at let and thought, "maybe they just felt like doing it that way".
Makes a lot more sense now.

this post was submitted on 19 Jun 2025
326 points (90.1% liked)

Programmer Humor

24374 readers
866 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