3 ms·
Yes, functional programming is very similar to OO. OO: class SomeType { <data> ; SomeOtherType function1() { this.whatever
by jrockway 17y ago
Yes, functional programming is very similar to OO.
OO:
class SomeType {
<data> ;
SomeOtherType function1() {
this.whatever ;
...
}
}
FP:
data SomeType ...
f1 :: SomeType -> SomeOtherType
f1 this = whatever this >> ...
Same idea, different syntax. (Type classes will allow polymorphism, if that's what you're after.)
You are thinking of the abstraction in terms of its implementation. There is no reason why a method in a class would physically be in that class; the class just acts as a namespace:
class Foo { method }
Foo.method();
and
(defmethod Foo.method ...)
(Foo.method)
are the same.