r/functionalprogramming • u/Neither-Acadia2395 • Nov 05 '23
Question Why is functional programming so hard
Throughout my entire degree till now, I’ve been taking OOP. Now I am in a FP course and I am struggling a lot. I understand it’s almost a total different thing. But I just failed a midterm in FP in Ocaml. I swear I could’ve solved the questions with my eyes closed in OOP. What am I doing wrong, why can’t I get a grasp of it. Any tips on how I should approach studying this.
78
Upvotes
View all comments
Show parent comment
1
u/Long_Investment7667 Nov 06 '23
My working theory is that it is not about functions vs classes or state management or side effects, or … , but rather polymorphism. The main (sometimes only) mechanism to implement something polymorphic in OO is virtual function dispatch. This can be best seen when using heterogeneous collections or a tree-like structure. One has to leverage virtual functions (through inheritance or interface implementation. For example the visitor pattern)