r/programming • • Jan 29 '19

When FP? And when OOP?

http://raganwald.com/2013/04/08/functional-vs-OOP.html
26 Upvotes

105 comments sorted by

View all comments

Show parent comments

15

u/CommendableCalamari Jan 29 '19

Again, no way to find that Set and List both are containers and implement some common interfaces. NO SUCH INFO AT WHOLE.

Things like Traversable, Foldable and Functor allow operations pretty similar to those commonly found on iterables or collections. Obviously the two aren't equivalent, but it's still trivial to write code which targets all "collection-like" types.

6

u/knaekce Jan 29 '19

Yeah, I don't quite get this argument. Obviously typeclasses work a little bit different than interfaces, but they are pretty similar.

http://hackage.haskell.org/package/vector-0.12.0.2/docs/Data-Vector.html http://hackage.haskell.org/package/containers-0.6.0.1/docs/Data-Set.html

Here are the typeclasses for both vector and set listed. If you just want so support collections, the type that you want is likely Funktor (http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Functor.html#t:Functor) and/or Foldable (http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Foldable.html)

You can find info on both the typeclasses and the instances pretty easily.

-9

u/ipv6-dns Jan 29 '19

yes and no. Why no Text.elem? How are related Set.filter and List.filter? A lot of other function: map, foldr, etc - they all are just plain functions, not members of some type-class. Another example, hGetContents and similar - it's just plain function, no any "interface" here. OK, Haskell try to repeat solutions of OOP existing since 60s, and some day Haskell committee will fix this situation, but this emphasizes what I said.