What are the benefits of using objects in a functional programming language?

What is the real reason for using objects in functional programming languages? I see that f # is a functional programming language that relies heavily on the object side when working with the ecosystem of .net classes. But besides this interaction with other assemblies / programs written in C #, why did someone decide to use objects to decompose the program in a functionally oriented language or style?

Does the style of the program combine help or an obstacle?

+4
source share
2 answers

Functional and object-oriented projects simplify various types of extensions. Given the discriminatory union in the functional setting, it is easy to determine any number of functions that work on this type, but it is difficult to add additional types to the type, since you will need to go back to add an additional case to each function whose template matches the type. On the other hand, given the base type (or interface) of the OO installation, it is easy to add new subtypes, but adding new operations to the base type is difficult because it potentially requires changing existing subtypes to add each new implementation.

Depending on the type of extensibility that is most significant for a given task, a functional or object-oriented approach may make more sense, so it’s nice to have both options. One popular approach is to use the functional approach β€œin the small” and the OO approach β€œin general” (for example, it is mentioned in this podcast with Luc Hoban).

+5
source

Objects provide encapsulation to facilitate large-scale programming.

What is the real reason for using objects in functional programming languages?

Objects are used in functional languages ​​for various reasons:

  • Mass structuring of programs.

  • Interaction with existing OOP code (for example, on the JVM or CLR).

  • Problems for which the possibility of expanding the class hierarchy with a large number of classes is a natural approach.

Does the style of the program combine help or an obstacle?

It may be help, but it would be nice to do it without a good reason.

0
source

Source: https://habr.com/ru/post/1338046/


All Articles