
On Tue, Jun 7, 2011 at 10:32 PM, Evan Laforge
Is this badly designed code that tries to mimic OO in a functional setting? If the answer is yes, how could I achieve same result (eg. testing the code that does command REPL) without defining type classes?
Here's how I do it:
data InteractiveState = InteractiveState { state_read :: IO Command , state_write :: Result -> IO () }
How about :
data InteractiveState io = InteractiveState { state_read :: io Command , state_write :: Result -> io () }
Then you don't even depend on some specific monad. I understand you can always (always?) encapsulate what is done through a type class by using a data containing functions. But then, is this not even closer to OO programming, an object that carries its own methods with itself, possibly with the additional overhead that *each* instance would have its own private references to possibly identical functions. Thanks, Arnaud