|
|
|
|
|
by substation13
1546 days ago
|
|
In F# (the most widely used ML?) expressions can be much more complicated than that, incorporating loops, conditionals etc. To illustrate: let x =
let mutable maxScore = 0
for item in items do
if item.Score > maxScore then
maxScore <- item.Score
maxScore
Compared to: const x =
(() => {
let maxScore = 0;
for (const item of items) {
if (item.score > maxScore) {
maxScore = item.Score;
}
}
return maxScore;
})();
Not necessarily the best way to write this (you would probably use a sequence library) but hopefully conveys the idea.Extension methods are definitely useful in OOP languages. However, a much cleaner language design is to remove the need for a "class" altogether and just have free-functions, function composition and a pipe operator. None of this is something you can't simulate in OOP / procedural languages, it's just much more clunky. |
|