Re: [Haskell] threading mutable state through callbacks

2004-10-13 Thread Marcin 'Qrczak' Kowalczyk
Jules Bean <[EMAIL PROTECTED]> writes: > Unless its possible to arrange haskell FFI bindings to have types in > MonadIO rather than IO... MonadIO is a class, not a type. Anyway, it's conceptually impossible to wrap a computation of an arbitrary monad in the MonadIO class into IO. It's not a techn

Re: [Haskell] threading mutable state through callbacks

2004-10-13 Thread Antony Courtney
Wolfgang Thaller wrote: > > 2) Evaluation order. > > That's what everyone has been fighting about. > [...] > >> The basic idea is that your entire program behaves as if in a giant >> 'mdo' block, ordered in module dependency order. > > > > What is module dependency order? There's no such thing when

RE: [Haskell] threading mutable state through callbacks

2004-10-13 Thread Simon Marlow
On 13 October 2004 03:36, Wolfgang Thaller wrote: > b) Some predetermined order, with semantics like mdo: > > John Meacham wrote: > >> The basic idea is that your entire program behaves as if in a giant >> 'mdo' block, ordered in module dependency order. I also like the mdo idea - in fact it oc

Re: [Haskell] threading mutable state through callbacks

2004-10-13 Thread Keean Schupke
There are stToIO and ioToST sunctions though (ioToST is unsafe)... Keean Jules Bean wrote: On 13 Oct 2004, at 13:14, MR K P SCHUPKE wrote: its almost commutative Does that have something to do with splitting the supply? That is an approach to getting unique values, I think. newIORef why not use

Re: [Haskell] threading mutable state through callbacks

2004-10-13 Thread Jules Bean
On 13 Oct 2004, at 13:14, MR K P SCHUPKE wrote: its almost commutative Does that have something to do with splitting the supply? That is an approach to getting unique values, I think. newIORef why not use 'newSTRef' and use the ST monad... In the context of my original question, the answer is that

Re: [Haskell] threading mutable state through callbacks

2004-10-13 Thread MR K P SCHUPKE
>its almost commutative Does that have something to do with splitting the supply? >newIORef why not use 'newSTRef' and use the ST monad... Keean. ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell

Re: [Haskell] threading mutable state through callbacks

2004-10-13 Thread Jules Bean
On 12 Oct 2004, at 22:49, MR K P SCHUPKE wrote: All we really need is a 'unique value monad' to give us unique values This sounds a lot like Clean's unique-types? No, that's a confusion of terminology. 'Unique types' are type which have only one member. 'RealWorld' in haskell is rather like one of

Re: [Haskell] threading mutable state through callbacks

2004-10-13 Thread John Meacham
On Wed, Oct 13, 2004 at 10:01:08AM +0100, Adrian Hey wrote: > On Wednesday 13 Oct 2004 3:36 am, Wolfgang Thaller wrote: > > b) Some predetermined order, with semantics like mdo: > > > > John Meacham wrote: > > > The basic idea is that your entire program behaves as if in a giant > > > 'mdo' block,

Re: [Haskell] threading mutable state through callbacks

2004-10-13 Thread Adrian Hey
On Wednesday 13 Oct 2004 3:36 am, Wolfgang Thaller wrote: > b) Some predetermined order, with semantics like mdo: > > John Meacham wrote: > > The basic idea is that your entire program behaves as if in a giant > > 'mdo' block, ordered in module dependency order. > > What is module dependency order?

Re: [Haskell] threading mutable state through callbacks

2004-10-13 Thread Udo Stenzel
Wolfgang Thaller <[EMAIL PROTECTED]> schrieb am 13.10.04 04:36:43: > 2) Evaluation order. > > That's what everyone has been fighting about. > > So what are our options? > > a) unsafePerformIO - like. > b) Some predetermined order, with semantics like mdo: c) same as b) plus unsafeInterleaveIO

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Wolfgang Thaller
Well, Wadler's Law of Language Design has been disproved. We seem to agree on the syntax, that is, global "foo <- bar" bindings, and we're actually discussing semantics. That's great! Just for the record, I want exactly what Adrian proposed. There seem to be two interesting points about the sema

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Glynn Clements
Vincenzo Ciancia wrote: > > Unfortunately, in this case the whole point of what people are trying > > to do with unsafePerformIO is to allow these things to be visible at > > the top level :-) > > Sometimes I get too much involved in what I think about, and forget the > original goal :) A littl

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Adrian Hey
On Tuesday 12 Oct 2004 10:19 pm, Jules Bean wrote: > It does matter for general IO operations at the top level. All I'm aiming for is to disambiguate programs (avoid the use of unsafePerformIO) in such a way that the programmer at least stands a reasonable chance of getting it right without compil

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Vincenzo Ciancia
On Wednesday 13 October 2004 00:00, Adrian Hey wrote: > Unfortunately, in this case the whole point of what people are trying > to do with unsafePerformIO is to allow these things to be visible at > the top level :-) Sometimes I get too much involved in what I think about, and forget the original

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Adrian Hey
On Tuesday 12 Oct 2004 10:47 pm, Marcin 'Qrczak' Kowalczyk wrote: > Adrian Hey <[EMAIL PROTECTED]> writes: > > The only real insanity with the current situation is the loss of > > referential transparency implied by the use of unsafePerformIO, > > which is why various pragma hacks and compiler swit

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Adrian Hey
On Tuesday 12 Oct 2004 8:43 pm, Vincenzo Ciancia wrote: > The objection was for cases like > > x :: Int <- someIOAction > y :: Int = x + 1 > > Note that both have Int type but the second is a pure value while the > first is the result of a computation. Well obviously if people are going to use it

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread MR K P SCHUPKE
>All we really need is a 'unique value monad' to give us unique values This sounds a lot like Clean's unique-types? Keean. ___ Haskell mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Marcin 'Qrczak' Kowalczyk
Adrian Hey <[EMAIL PROTECTED]> writes: > The only real insanity with the current situation is the loss of > referential transparency implied by the use of unsafePerformIO, > which is why various pragma hacks and compiler switches need to be > used (in order to prevent inappropriate substitutions).

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Jules Bean
On 12 Oct 2004, at 20:25, Adrian Hey wrote: On Tuesday 12 Oct 2004 6:28 pm, Jules Bean wrote: On 12 Oct 2004, at 14:08, Adrian Hey wrote: x <- someAction y <- someAction(x) I would say keep things as they currently are with the unsafePerformIO solution, I.E. Order unspecified, the action that crea

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Jules Bean
On 12 Oct 2004, at 18:59, Marcin 'Qrczak' Kowalczyk wrote: Jules Bean <[EMAIL PROTECTED]> writes: I think what people are trying to suggest is an 'initialization phase' in the IO monad, which takes place "before" the pure functions are defined. If it was done before, what could you use to specify i

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Vincenzo Ciancia
On Tuesday 12 October 2004 21:25, Adrian Hey wrote: > I've never really understood what people mean by things being > "inside" and "outside" the IO monad :-( Inside the IO monad means "correctly sequenced together with other IO operations which are inside the IO monad". It's called "inside" since

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Adrian Hey
On Tuesday 12 Oct 2004 6:28 pm, Jules Bean wrote: > On 12 Oct 2004, at 14:08, Adrian Hey wrote: > >> x <- someAction > >> y <- someAction(x) > > > > I would say keep things as they currently are with the unsafePerformIO > > solution, I.E. Order unspecified, the action that creates a particular > >

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Marcin 'Qrczak' Kowalczyk
Jules Bean <[EMAIL PROTECTED]> writes: > I think what people are trying to suggest is an 'initialization > phase' in the IO monad, which takes place "before" the pure > functions are defined. If it was done before, what could you use to specify initial value of such a variable? Only literals? Con

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Jules Bean
On 12 Oct 2004, at 14:08, Adrian Hey wrote: x <- someAction y <- someAction(x) I would say keep things as they currently are with the unsafePerformIO solution, I.E. Order unspecified, the action that creates a particular top level thing is executed only once, when the value of thing is demanded (pe

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Adrian Hey
On Tuesday 12 Oct 2004 1:44 pm, Vincenzo Ciancia wrote: > On Tuesday 12 October 2004 12:23, Adrian Hey wrote: > > I don't know what more > > general-purpose extension you have in mind, but couldn't you just > > borrow from do syntax at the top level > > I think that the problem is with the order o

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Vincenzo Ciancia
On Tuesday 12 October 2004 12:23, Adrian Hey wrote: > I don't know what more > general-purpose extension you have in mind, but couldn't you just > borrow from do syntax at the top level I think that the problem is with the order of execution of these bindings. For example ghci supports top-level

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Marcin 'Qrczak' Kowalczyk
"Simon Marlow" <[EMAIL PROTECTED]> writes: > I'd like to add that while the implementation might be a little unsafe, > there's no problem in principle with the semantics of top-level IORefs. > We could add such a thing as a GHC extension, but it would be nice if it > were an instance of a more gen

Re: [Haskell] threading mutable state through callbacks

2004-10-12 Thread Adrian Hey
On Monday 11 Oct 2004 4:03 pm, Simon Marlow wrote: > On 08 October 2004 19:18, Sven Panne wrote: > > c) Give up any hope of clean semantics and simply use a common hack > > like: > > > >{-# NOINLINE myGlobalVar #-} > >myGlobalVar :: IORef Int > >myGlobalVar = unsafePerformIO

RE: [Haskell] threading mutable state through callbacks

2004-10-11 Thread Simon Marlow
On 08 October 2004 19:18, Sven Panne wrote: > Jules Bean wrote: >> [...] Unfortunately, it's not going to work. It's not going to work >> because some of the procedures take callbacks, and the callbacks are >> values of type IO (). I can see two solutions to this: >> >> a) revert to using an IORe

Re: [Haskell] threading mutable state through callbacks

2004-10-08 Thread Sven Panne
Jules Bean wrote: [...] Unfortunately, it's not going to work. It's not going to work because some of the procedures take callbacks, and the callbacks are values of type IO (). I can see two solutions to this: a) revert to using an IORef [...] b) write the callbacks as values of type StateT Env

[Haskell] threading mutable state through callbacks

2004-10-07 Thread Jules Bean
Hi, I've been playing with some haskell bindings which basically bind C procedures in the IO monad. To write 'interesting' programs, you often need to manage your own state in addition to the implicit IO state. I have been allocating references with newIORef and then passing them around all my