Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is functional programming a subset of imperative programming?

One of the main characteristics of functional programming is the use of side-effectless functions. However, this can be done in an imperative language also. The same is true for recursion and lambda functions (for example C++0x). Therefore I wonder whether imperative programming languages are a superset of functional ones.

like image 227
Dimitri C. Avatar asked Nov 23 '09 14:11

Dimitri C.


People also ask

Is functional programming imperative or declarative?

Functional programming is a form of declarative programming. In contrast, most mainstream languages, including object-oriented programming (OOP) languages such as C#, Visual Basic, C++, and Java, were designed to primarily support imperative (procedural) programming.

What is different between imperative languages and functional programming languages?

The imperative languages facilitate the computation using the state changes. The functional languages facilitate the functions that the program represents, instead of only stating changes as the program executes, statement by statement.

What types of programming are imperative?

Procedural and object-oriented programming (OOP) languages fall under imperative programming, such as C, C++, C#, and Java.


2 Answers

I can't really say whether they are subset of one another. What I can tell, though, that (except for really esoteric languages) they are all Turing-complete, which means that in the end they're all equally powerful, but not neccesarily equally expressive.

like image 68
Anton Gogolev Avatar answered Sep 20 '22 14:09

Anton Gogolev


One way to look at it (not saying it's the right way 'cos I'm not a lang designer or theorist by any means) is that if the language is essentially converted to something else then that 'something else' must be the superset of the source. So bytecode is necessarily a superset of Java. .NET IL is a superset of C# and of F#. The functional constructs in C# (i.e. LINQ) are thus a subset of the imperative constructs of IL.

Since machine language is imperative, you could take the position that, therefore, all languages are imperative, because they are just abstractions useful for humans that are then boiled away by the compiler to procedural, imperative machine code.

like image 35
Kevin Won Avatar answered Sep 17 '22 14:09

Kevin Won