Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-22 Thread Henning Thielemann
On Fri, 20 Feb 2009, Louis Wasserman wrote: Hmmm.  That's probably a better framework to draw on for the general array interface. For a list of all such low-level arrays, see: http://www.haskell.org/haskellwiki/Storable_Vector StorableVectors can also be manipulated in ST

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-20 Thread Ryan Ingram
Yeah, I totally forgot about arrays. But if you're interested in pure computations that use arrays for intermediate results, maybe uvector[1] is what you are looking for instead? -- ryan [1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/uvector On Thu, Feb 19, 2009 at 2:14 PM,

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-20 Thread Louis Wasserman
Hmmm. That's probably a better framework to draw on for the general array interface. The real goal, though, was to be able to abstract out the array usage: specifically: stateful-mtl provided MonadST and then an ArrayT that drew on the state thread from a MonadST to hold its own STArray (which I

RE: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-19 Thread Sittampalam, Ganesh
Henning Thielemann wrote: On Mon, 16 Feb 2009, Louis Wasserman wrote: Overnight I had the following thought, which I think could work rather well.  The most basic implementation of the idea is as follows: class MonadST s m | m - s where liftST :: ST s a - m a instance MonadST s (ST

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-19 Thread Louis Wasserman
It does. In the most recent version, the full class declaration runs class MonadST m where type StateThread m liftST :: ST (StateThread m) a - m a and the StateThread propagates accordingly. Louis Wasserman wasserman.lo...@gmail.com On Thu, Feb 19, 2009 at 2:10 AM, Sittampalam, Ganesh

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-19 Thread Ryan Ingram
So, why not use this definition? Is there something special about ST you are trying to preserve? -- minimal complete definition: -- Ref, newRef, and either modifyRef or both readRef and writeRef. class Monad m = MonadRef m where type Ref m :: * - * newRef :: a - m (Ref m a) readRef

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-19 Thread Louis Wasserman
Oh, sweet beans. I hadn't planned to incorporate mutable references -- my code uses them highly infrequently -- but I suppose that since mutable references are really equivalent to single-threadedness where referential transparency is concerned, that could be pulled off -- I would still want a

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-19 Thread Louis Wasserman
Ryan, I didn't get your question after the first read, so here's an actual answer to it -- What I want to preserve about ST is the existence of a guaranteed safe runST, really. I tend to do algorithms and data structures development, which almost never requires use of IO, or references of any

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-18 Thread Henning Thielemann
On Mon, 16 Feb 2009, Louis Wasserman wrote: Overnight I had the following thought, which I think could work rather well.  The most basic implementation of the idea is as follows: class MonadST s m | m - s where liftST :: ST s a - m a instance MonadST s (ST s) where ... instance MonadST s m

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-18 Thread Henning Thielemann
On Mon, 16 Feb 2009, Louis Wasserman wrote: I just posted stateful-mtl and pqueue-mtl 1.0.2, making use of the new approach to single-threaded ST wrapping.  I discovered while making the modifications to both packages that the MonadSTTrans type class was unnecessary, enabling a cleaner

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-18 Thread Louis Wasserman
Yes, it really is like MonadIO -- just capable of being used to produce guaranteed purely functional results ^^ Louis Wasserman wasserman.lo...@gmail.com On Wed, Feb 18, 2009 at 5:43 PM, Henning Thielemann lemm...@henning-thielemann.de wrote: On Mon, 16 Feb 2009, Louis Wasserman wrote: I

RE: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-16 Thread Sittampalam, Ganesh
: haskell-cafe-boun...@haskell.org [mailto:haskell-cafe-boun...@haskell.org] On Behalf Of Louis Wasserman Sent: 16 February 2009 03:31 To: Dan Doel Cc: Henning Thielemann; haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl Okay, I tested it out and the arrow

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-16 Thread Josef Svenningsson
On Mon, Feb 16, 2009 at 2:30 AM, wren ng thornton w...@freegeek.org wrote: Louis Wasserman wrote: I follow. The primary issue, I'm sort of wildly inferring, is that use of STT -- despite being pretty much a State monad on the inside -- allows access to things like mutable references?

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-16 Thread minh thu
2009/2/16 Josef Svenningsson josef.svennings...@gmail.com: On Mon, Feb 16, 2009 at 2:30 AM, wren ng thornton w...@freegeek.org wrote: Louis Wasserman wrote: I follow. The primary issue, I'm sort of wildly inferring, is that use of STT -- despite being pretty much a State monad on the inside

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-16 Thread Louis Wasserman
*Subject:* Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl Okay, I tested it out and the arrow transformer has the same problem. I realized this after I sent the last message -- the point is that at any particular point, intuitively there should be exactly one copy of a State# s for each

RE: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-16 Thread Sittampalam, Ganesh
: Louis Wasserman [mailto:wasserman.lo...@gmail.com] Sent: 16 February 2009 16:01 To: Sittampalam, Ganesh Cc: Dan Doel; Henning Thielemann; haskell-cafe@haskell.org Subject: Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl Overnight I had the following thought, which I think could work rather

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-16 Thread Louis Wasserman
. -- *From:* Louis Wasserman [mailto:wasserman.lo...@gmail.com] *Sent:* 16 February 2009 16:01 *To:* Sittampalam, Ganesh *Cc:* Dan Doel; Henning Thielemann; haskell-cafe@haskell.org *Subject:* Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl Overnight I had

RE: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-16 Thread Sittampalam, Ganesh
: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl But the m - s dependency will have been removed by the time runST gets a hold of it! It works, I just tested it. *Control.Monad.Array.ArrayM :t runST (runArrayT 5 Nothing getContents) runST (runArrayT 5 Nothing getContents) :: [Maybe

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-16 Thread Louis Wasserman
somewhere. -- *From:* Louis Wasserman [mailto:wasserman.lo...@gmail.com] *Sent:* 16 February 2009 16:17 *To:* Sittampalam, Ganesh *Cc:* Dan Doel; Henning Thielemann; haskell-cafe@haskell.org *Subject:* Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-16 Thread Ryan Ingram
Don't use the data (context) = type = constructors syntax, it doesn't do what you want. All it does is add the context to the constructor B while not providing it to any of the functions that use it. A better solution is data Bar a = forall b. Foo a b = B a b or, equivalently, using GADT

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-16 Thread Dan Doel
On Monday 16 February 2009 8:44:21 am Josef Svenningsson wrote: On Mon, Feb 16, 2009 at 2:30 AM, wren ng thornton w...@freegeek.org wrote: Louis Wasserman wrote: I follow. The primary issue, I'm sort of wildly inferring, is that use of STT -- despite being pretty much a State monad on the

RE: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-16 Thread Sittampalam, Ganesh
Dan Doel wrote: Someone already mentioned using Dynamic as an alternate base (for instance, use a Map of dynamics for underlying storage). Of course, the implementation of Dynamic in GHC uses unsafeCoerce, just like ST, so you may not count that. However, using GADTs, you can implement

[Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-15 Thread Louis Wasserman
Hello all, I just released two new packages on Hackage, stateful-mtl and pqueue-mtl. Stateful-mtl provides an ST monad transformer, several useful operations on generic monad transformers, and a monad transformer intended to cleanly externally wrap operations on a mutable array (including

RE: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-15 Thread Sittampalam, Ganesh
Stateful-mtl provides an ST monad transformer, Is this safe? e.g. does it work correctly on [], Maybe etc? If not this should be flagged very prominently in the documentation. Cheers, Ganesh == Please access the

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-15 Thread Reid Barton
On Sun, Feb 15, 2009 at 09:59:28PM -, Sittampalam, Ganesh wrote: Stateful-mtl provides an ST monad transformer, Is this safe? e.g. does it work correctly on [], Maybe etc? If not this should be flagged very prominently in the documentation. It is not safe: it has the same problem as

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-15 Thread Louis Wasserman
I follow. The primary issue, I'm sort of wildly inferring, is that use of STT -- despite being pretty much a State monad on the inside -- allows access to things like mutable references? More serious question: The issue of nondeterministic branching and the State monad is something that's

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-15 Thread Henning Thielemann
On Sun, 15 Feb 2009, Louis Wasserman wrote: I follow.  The primary issue, I'm sort of wildly inferring, is that use of STT -- despite being pretty much a State monad on the inside -- allows access to things like mutable references? I assume that ST must always be the most inner monad, like

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-15 Thread Louis Wasserman
Well, it makes me sad, I guess. pqueue-mtl provides an array-backed heap monad transformer that is supposed to keep its own ST thread, if only for the sake of retaining a purely functional interface without any externally visible forall'd types, which is perfectly fine in most cases, but I'd have

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-15 Thread Ryan Ingram
You can roll your own pure STT monad, at the cost of performance: -- Do not export any of these constructors, just the types STT and STTRef. data W = forall a. W !a data Heap s = Heap !Int !(IntMap W) newtype STT s m a = STT (StateT (Heap s) m a) deriving (Monad, MonadTrans, MonadIO, insert other

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-15 Thread Louis Wasserman
The module I put together already has everything I'd need to do it in terms of an IntMap with much less work than that -- the generic MonadArray type class has implementations both in terms of ST and in terms of an IntMap already. Only three changes in the Heap implementation would be needed: two

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-15 Thread wren ng thornton
Louis Wasserman wrote: I follow. The primary issue, I'm sort of wildly inferring, is that use of STT -- despite being pretty much a State monad on the inside -- allows access to things like mutable references? That's exactly the problem. The essential reason for ST's existence are STRefs

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-15 Thread Louis Wasserman
Hello all, I just uploaded stateful-mtl and pqueue-mtl 1.0.1. The ST monad transformer and array transformer have been removed -- I've convinced myself that a heap transformer backed by an ST array cannot be referentially transparent -- and the heap monad is now available only as a basic monad

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-15 Thread Dan Doel
On Sunday 15 February 2009 9:44:42 pm Louis Wasserman wrote: Hello all, I just uploaded stateful-mtl and pqueue-mtl 1.0.1. The ST monad transformer and array transformer have been removed -- I've convinced myself that a heap transformer backed by an ST array cannot be referentially

Re: [Haskell-cafe] ANNOUNCE: pqueue-mtl, stateful-mtl

2009-02-15 Thread Louis Wasserman
Okay, I tested it out and the arrow transformer has the same problem. I realized this after I sent the last message -- the point is that at any particular point, intuitively there should be exactly one copy of a State# s for each state thread, and it should never get duplicated; allowing other