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

2011-06-07 Thread Arnaud Bailly
Hello, In a recent thread, it has been asserted that defining type class is something you seldom need when programming in Haskell. There is one thing that as non-professional Haskell programmer I found type-classes useful for: Testing. This is probably very OO and is pretty much influenced by

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

2011-06-07 Thread 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

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

2011-06-07 Thread Arnaud Bailly
On Tue, Jun 7, 2011 at 10:32 PM, Evan Laforge qdun...@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

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

2011-06-07 Thread Evan Laforge
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 () } I guess you could, but I like it

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

2011-06-07 Thread Brandon Allbery
On Tue, Jun 7, 2011 at 16:16, Arnaud Bailly arnaud.oq...@gmail.com wrote: For example, while designing some program (a game...) I defined a type class thus: class (Monad io) = CommandIO io where   readCommand  :: io Command   writeResult  :: CommandResult - io () This is in fact one of the

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

2011-06-07 Thread Yves Parès
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? Why would that be badly designed? And why would that be more OO? IMO it is a perfectly

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

2011-06-07 Thread Yves Parès
...and the other one being operational (which I find simpler). 2011/6/8 Brandon Allbery allber...@gmail.com On Tue, Jun 7, 2011 at 16:16, Arnaud Bailly arnaud.oq...@gmail.com wrote: For example, while designing some program (a game...) I defined a type class thus: class (Monad io) =