|
|
|
|
|
by quickthrower2
2054 days ago
|
|
And also what is an 'object'? Haskell has a decent system for building up complex data structures. You can write functions for those. Those data structures + those functions are kind of "an object" from the OO world (data + methods). The differences are: * Inheritance - well Haskell has many kinds of polymorphism so it doesn't need it. * Hiding data - well Haskell can hide data using smart constructors, you don't need an explicit private keyword * Interfaces - covered by typeclasses but they do a lot more! Also without any of the above you can create object-like things with just closures. If a scope has access to 3 variables in scope, it's "kinda" like an OO object with 3 member variables. You can create new scopes in a for loop, which is like creating many new object. It's a stretch but the underlying concept of something owning other things is still there. |
|
And in this setting, the type of that datastructure containing the functions can act as an interface.
A trap that OO programmers sometimes fall into with Haskell is to try to emulate OO interfaces using existential types + typeclass interfaces but that is a bit of an antipattern.