Hacker News new | ask | show | jobs
by shortrounddev2 944 days ago
Has anyone else noticed that functional languages go heavy on the special keywords and operators? It feels like theres a larger cognitive load (more specific keywords to memorize) when learning languages like F# or OCaml compared to C or Python or Java
4 comments

Clojure doesn't. I'd really, really love to see a fast, statically-typed, functional lisp.
Carp - https://github.com/carp-lang/Carp - "A statically typed lisp, without a GC, for real-time applications." where it's "Ownership tracking enables a functional programming style while still using mutation of cache-friendly data structures under the hood".
You might like Coalton, which is statically typed, functional language embedded within Common Lisp. However, it hasn't reached version 1.0 yet.

https://github.com/coalton-lang/coalton

Actually they both (and OCaml has a whole lot of almost never used OOP - that's where the O comes from) have _way_ less "syntax" than Python or Java.
I just did some quick math. If you count all the keywords and operators for F# in microsoft's documentation, you come to 150 symbols. This doesn't include the nullary operators (of which there are 14)

Counting all the java operators and keywords, you get 84. This doesn't include assignment operators like "+=" or "-=" (11 such operators).

ChatGPT tells me that python has 36 keywords and 28 operators (not including the 13 assignment operators). This seems low and may be missing some syntactical sugar operators, but even then 64 is a far lower number than F#'s 150. Much debate could be had about which of these operators are fair to count or not, but it seems preliminarily that the data supports the position that functional programming languages (or at least F#) tend to go heavy on special keywords and operators

You're right, there actually are more. Interesting, I "feel" the opposite.

Haskell (55 + some more, because of the grouping): https://wiki.haskell.org/Keywords

F# https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...

OCaml: https://v2.ocaml.org/manual/lex.html#sss:keywords

Python: https://github.com/python/cpython/blob/3.12/Lib/keyword.py

Java (I think these are the current ones): https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_k...

A few of the Haskell ones are introduced by extensions, so they're not part of the language proper.
Yes, I know. Same for OCaml with PPXs. That was just to show that even Haskell has many, even though most operators aren't keywords but "normal" infix functions (of type classes).
> even though most operators aren't keywords but "normal" infix functions

yes, that is also important to mention

Can you clarify what you mean? I don't think Roc actually has that many keywords or operators in total. I would bet that C has more keywords that Roc.

I do agree that default convention may rely heavily on a few syntaxes that aren't as common in procedural or OO languages.

Still way better than doing C++, speaking as someone that likes C++ since the Turbo C++ for MS-DOS days,