[Haskell-cafe] wondering about a MonadIO instance for a heap data type

2012-07-11 Thread Qi Qi
Hi, I was wondering about creating an instance of MonadIO for a heap data. Any hints? data Heap a = E | T Int a (Heap a) (Heap a) deriving (Eq, Ord, Read, Show) The reason is that I want to use liftIO during a heapsort to print out intermediate results. Thanks. Qi Qi

Re: [Haskell-cafe] wondering about a MonadIO instance for a heap data type

2012-07-11 Thread Eugene Kirpichov
Use Debug.Trace. It does not make sense to declare that heap is a monad, as a monad is an abstraction of sequencing computations, and a heap is not an abstraction of sequencing computations at all. You don't make your String class implement the rendering engine interface just because you want

Re: [Haskell-cafe] wondering about a MonadIO instance for a heap data type

2012-07-11 Thread Qi Qi
List [] is a monad, why not for heap data. Heap data could be an instance of Monad too. I have the heapsort function, and just wanted to rewrite a verbose version of it by using liftIO. But I would look into Debug.Trace. Thanks for your hint. Qi On Wednesday, July 11, 2012 5:28:17 PM UTC-5,

Re: [Haskell-cafe] wondering about a MonadIO instance for a heap data type

2012-07-11 Thread Brandon Allbery
On Wed, Jul 11, 2012 at 8:00 PM, Qi Qi qiqi...@gmail.com wrote: List [] is a monad, why not for heap data. Heap data could be an instance of Monad too. Only if you can define a meaningful semantics for it. Lists aren't a monad because of liftIO, but because the monad pattern means something

Re: [Haskell-cafe] wondering about a MonadIO instance for a heap data type

2012-07-11 Thread Conrad Parker
On 12 July 2012 06:19, Qi Qi qiqi...@gmail.com wrote: Hi, I was wondering about creating an instance of MonadIO for a heap data. Any hints? data Heap a = E | T Int a (Heap a) (Heap a) deriving (Eq, Ord, Read, Show) The reason is that I want to use liftIO during a heapsort to print

Re: [Haskell-cafe] wondering about a MonadIO instance for a heap data type

2012-07-11 Thread Eugene Kirpichov
List is a monad because it has an associated way of sequencing computations: namely, collect results of the second computation invoked on all results of the first computation. That's not because List is a data structure (similarly to Heap), it's because it is associated with the computational