Comparison of programming languages (functional programming)
This page provides the comparison tables of functional programming instructions between programming languages. Comparison of basic instructions of imperative paradigm is provided by the comparison of basic instructions.
List operations
Function applications and lists
For brevity, these words will be have the specified meanings in the following tables :;
funcN
: A function. May be unary or n-ary.;
pred
: Unary function returning a Boolean value. .;
list
: The list being operated on.;
args
: Comma-separated list of one or more argument names, in the form of arg1, arg2,..., argn
.;
pattern
: A pattern, in languages with pattern matching.;
val
: Any relevant value, depending on context.identity lambda | lambda | map | apply | filter | fold | sum | |
Python | lambda x: x | lambda args: expr | map | nfunc | filter | functools.reduce | sum |
Mathematica | #& | & Function | Map func /@ list | Apply nfunc@@args | Select | Fold | Apply Plus@@list |
C# | x => x | => expr | Enumerable.Select | Requires reflection | Enumerable.Where | Enumerable.Aggregate Enumerable.Aggregate | Enumerable.Sum Enumerable.Sum |
Visual Basic.NET | Function x | Function expr | Enumerable.Select | Requires reflection | Enumerable.Where | Enumerable.Aggregate Enumerable.Aggregate | Enumerable.Sum Enumerable.Sum |
F# | id fun x -> x | fun pattern -> expr | Seq.map func list | Requires reflection | Seq.filter pred list | Seq.fold func2 val list | Seq.sum list Seq.sumBy func list |
Numerical operations on lists
;comp
: a binary function that returns a value indicating sort order.sort | max | min | |
Python | sorted | max | min |
Mathematica | Sort | Max | Min |
C# | Enumerable.OrderBy | Enumerable.Max | Enumerable.Min |
Visual Basic.NET | Enumerable.OrderBy | Enumerable.Max | Enumerable.Min |
F# | Seq.sort list Seq.sortBy comp list | seq.max seq.maxBy func list | seq.min seq.minBy func list |
Iterations on lists
group by | |
Python | itertools.groupby |
Mathematica | GroupBy |
C# | Enumerable.GroupBy |
Visual Basic.NET | Enumerable.GroupBy |
F# | seq.groupBy func list |
Generating lists by combinatorics tools
;start: first value of range.;step: increment of range.
;count: number of items in range.
;last: inclusive last value of range.
;end: exclusive last value of range.
Generate range | Infinite range | |
Python | xrange range | itertools.count |
C# | Enumerable.Range | Enumerable.Range |
Visual Basic.NET | Enumerable.Range | Enumerable.Range |
F# | seq | Seq.initInfinite func |