FP has control flow, but one that is rather determined by arithemtic laws and non-strict evaluation than the lexical position of statements/expressions. An operator can be associative, commutative, distributive. Monoid, for instance, is associative, but not commutative, which gives you a precise and predicable control flow. The entire Monad type class exists to compose statements and thus allow modelling control flows similar to those in imperative programming.
Doesn't control flow imply statements? My understanding is pure functional programming languages do not have statements and control flow is an imperative only construct.
// dropping the parenthesis for clarity
f g x
// adding parenthesis to reveal left associativity of function application
(f g) x
Function application establishes a left associative evaluation order. Function composition establishes a right associative one.
With monads you define evaluation order of function composition with side effects (first example).
Now if you refer to the purely functional theory (lambda calculus) you are almost right: There are different evaluation strategies and the compiler decides which one is applied.
You can even write: Loosely speaking there is no evaluation order in FP, but this is a simplification.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
FP has control flow, but one that is rather determined by arithemtic laws and non-strict evaluation than the lexical position of statements/expressions. An operator can be associative, commutative, distributive. Monoid, for instance, is associative, but not commutative, which gives you a precise and predicable control flow. The entire Monad type class exists to compose statements and thus allow modelling control flows similar to those in imperative programming.
Doesn't control flow imply statements? My understanding is pure functional programming languages do not have statements and control flow is an imperative only construct.
Consider the following computation:
You need an order for that. Another example:
Function application establishes a left associative evaluation order. Function composition establishes a right associative one.
With monads you define evaluation order of function composition with side effects (first example).
Now if you refer to the purely functional theory (lambda calculus) you are almost right: There are different evaluation strategies and the compiler decides which one is applied.
You can even write: Loosely speaking there is no evaluation order in FP, but this is a simplification.