دنبال کننده ها

۱۳۹۶ شهریور ۱۰, جمعه

functional programming - OCaml: Rarely use classes and objects, if at all

[ad_1]



Sorry for the potentially misleading title, but that quote is from Real World OCaml, and it stumped me a little bit. I realize that the following may not be a "good" S.O. question, as it is not totally objective and has some room for discussion to creep in. However, I think any reasonably acceptable answer would be very helpful to someone making the transition from OOP, even at the sake of some discussion.



Let's say your designing a scenario in an OOP language where you have an array of Car objects and you want to find all of the sports cars. To do this, you would simply perform a filter on that array, calling the isSportsCar() method on each object.



How would a similar scenario be done in OCaml, without using classes or objects? First-class modules? Records, with functions that operate on them? Or would a seasoned OCaml-er simply avoid this type of scenario outright and that's why they rarely, if ever, have to uses objects and classes?




[ad_2]

لینک منبع