Hi Luke,

Apologies, I think I got bitten by unsafePerformIO.

The reason it wasn't in the IO monad is that the Vector created from the Buffer is supposed to be immutable.

I've changed the API so that:

main = do
   buf <- newBuffer 10 :: IO (Buffer Int)
   pushNextElement buf 1
   v1 <- toVector buf
   v2 <- toVector buf
   print $ V.toList v1
   pushNextElement buf 2
   print $ V.toList v2

does as expected.


Thanks,

Vivian


On 15 February 2011 17:08, Luke Palmer <lrpalmer@gmail.com> wrote:
This interface is an outlaw.

main = do
   buf <- newBuffer 10 :: IO (Buffer Int)
   pushNextElement buf 1
   let v1 = V.toList (toVector buf)
       v2 = V.toList (toVector buf)
   print v1
   pushNextElement buf 2
   print v2

Despite v1 and v2 being defined to equal the exact same thing, this
program prints two distinct lines.

toVector depends on the current state of the buffer.  If this is to be
a law-abiding interface, toVector must return a value in IO:

   toVector :: (Storable a) => Buffer a -> IO (Vector a)

Luke

On Mon, Feb 14, 2011 at 7:28 PM, Alexander McPhail
<haskell.vivian.mcphail@gmail.com> wrote:
> Hi,
>
> I have uploaded a small package, vector-buffer, to hackage.  It provides a
> buffer that can be turned into a Data.Vector.Storable.  The mapM* functions
> map from the oldest element, not the first.  Similarly for the derived
> Vector.
>
> Feature requests etc. welcome.
>
> Vivian
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>



--
---
yolar et elver.
---

DISCLAIMER

This transmission contains information that may be confidential. It is intended for the named addressee only. Unless you are the named addressee you may not copy or use it or disclose it to anyone else.