[Haskell-cafe] Non-advanced usage of Type classes

Arnaud Bailly arnaud.oqube at gmail.com
Tue Jun 7 22:43:31 CEST 2011


On Tue, Jun 7, 2011 at 10:32 PM, Evan Laforge <qdunkan at gmail.com> wrote:

> > 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110607/6edef6ab/attachment.htm>


More information about the Haskell-Cafe mailing list