5 ms·
A record of functions permits polymorphism in behavior, but I'm not clear on how it can provide polymorphism in state or structure. I'm certainly no expert in
by djur 12y ago
A record of functions permits polymorphism in behavior, but I'm not clear on how it can provide polymorphism in state or structure.
I'm certainly no expert in pure FP so there may be something I'm missing, but if the operations have to produce a change in the state of an entity, each one of the functions would have to both receive and return a state, right? Or you use a record of closures, each which returns a new record of closures?
It seems to me that in both cases you're discarding a lot of the benefits of Haskell's type system.
- cousin_it 12y agoFor what it's worth, I agree that a graph of stateful objects referencing each other is much easier to express in an OO language than in a pure functional language. There are many functional solutions, but none of them are very nice IMO. Maybe that's one reason to use an impure functional language like ML, which I consider an overall better language than Haskell.
- djur 12y agoI think we agree on this one. I've really been enjoying using OCaml exactly because I can make use of mutable state or OO-style polymorphism when I want, but otherwise it feels very natural to write pure functional code. All I need to do is wrap my head around functors and first-class modules and I'll actually feel like I understand it well enough to use it for real work.