Is there any interest in implementing a top level "<-" to run monadic code? Currently this sort of thing is done with unsafePerformIO and switching off inlining with some pragma. Indeed, the 'atomically' haddock actually advises doing this to declare top-level TVars. The same trick is used in the source of Data.Unique and System.Random. This is bad Haskell. To avoid observation of effects, etc., we would need a new monad rather than IO. There would be equivalents of IO functions such as these: newIORef newMVar newTVarIO newUnique I can think of two uses: 1. Global mutable state. For instance, here's the count variable for Data.Unique rewritten: uniqSource :: MVar Integer uniqSource <- newMVarTL 0 Isn't that much nicer? <http://haskell.org/haskellwiki/Top_level_mutable_state> 2. Solving the expression problem using open witnesses, a recent hobby-horse of mine. For instance, here's a simple scheme for extensible exceptions using top-level "<-": -- declare exception carrying an Int myException :: Exn Int <- newExn -- throw with 5 foo = do ... throw myException 5 -- catch, print the Int bar = catch foo myException (\i -> putStrLn (show i)) I already have code for this, except with an unsafe hack to do the "<-" declaration: <http://hackage.haskell.org/packages/archive/open-witness/0.1.1/doc/html/Data-OpenWitness-Exception.html> My open-witness package, which also shows how to do Typeable/Dynamic safely: <http://hackage.haskell.org/cgi-bin/hackage-scripts/package/open-witness> -- Ashley Yakeley Seattle, WA
On Sun, Aug 24, 2008 at 7:12 PM, Ashley Yakeley <ashley@semantic.org> wrote:
Is there any interest in implementing a top level "<-" to run monadic code?
This is actually implemented in jhc. See the 'top level actions' section of http://repetae.net/computer/jhc/manual.html -Edward Kmett
(Moving to Haskell cafe) Edward Kmett wrote:
On Sun, Aug 24, 2008 at 7:12 PM, Ashley Yakeley <ashley@semantic.org> wrote:
Is there any interest in implementing a top level "<-" to run monadic code?
This is actually implemented in jhc. See the 'top level actions' section of http://repetae.net/computer/jhc/manual.html
Gosh! I was always quite impressed by Johns determination to write a Haskell compiler and by his self discipline in resisting the temptation to fix everything that was wrong with Haskell and keep to standards :-) I implemented my own ACIO monad a while ago (which is of course quite useless without top level <- bindings) and it turned out that there was quite a lot that could go in here. The only problem seemed to be that some things that seemed perfectly reasonable to create via ACIO had *IO* finalisers associated with them, which didn't feel right to me. But if you think about how finalisers get run I'm inclined to think we should insist that they are ACIO too. Regards -- Adrian Hey
On Mon, Aug 25, 2008 at 04:55:05PM +0100, Adrian Hey wrote:
(Moving to Haskell cafe)
Edward Kmett wrote:
On Sun, Aug 24, 2008 at 7:12 PM, Ashley Yakeley <ashley@semantic.org> wrote:
Is there any interest in implementing a top level "<-" to run monadic code?
This is actually implemented in jhc. See the 'top level actions' section of http://repetae.net/computer/jhc/manual.html
Gosh! I was always quite impressed by Johns determination to write a Haskell compiler and by his self discipline in resisting the temptation to fix everything that was wrong with Haskell and keep to standards :-)
Heh. :) I have not had much time recently to work on jhc. but I hope to pick it up full steam soon. There have been a lot of strong contributers in the community as well. (sigh. day job syndrome).
I implemented my own ACIO monad a while ago (which is of course quite useless without top level <- bindings) and it turned out that there was quite a lot that could go in here.
Yeah, I based my design on what I thought was the 'community consensus' on how they should look the last time the discussion came up. (not counting those that were adamantly opposed to the idea alltogether ;) ) I forgot who came up with the original ACIO idea, but I'd give them props in the manual if they wish.
The only problem seemed to be that some things that seemed perfectly reasonable to create via ACIO had *IO* finalisers associated with them, which didn't feel right to me. But if you think about how finalisers get run I'm inclined to think we should insist that they are ACIO too.
Yeah, this sounds like a great idea. there were a whole lot of issues dealing with finalizers and concurrency, and restricting them in some way similar to ACIO might be good... however, you want something a little weaker than ACIO I think. it must satisfy the ACIO conditions, but _may_ assume its argument (the item being collected) is never referenced again. hence something like 'free' is okay which wouldn't be if other references to the object exist. do you think that is 'formal' enough of a description? seems clear enough if ACIO is well defined which I think it is. John -- John Meacham - ⑆repetae.net⑆john⑈
Hello Ashley, Monday, August 25, 2008, 3:12:18 AM, you wrote:
Is there any interest in implementing a top level "<-" to run monadic code?
yes, definitely. as it's hard to develop "real" app w/o using global vars, h98 still remains "unreal" language but from my POV it's important to push this feature into haskell standard -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
On Tue, 2008-08-26 at 19:01 +0400, Bulat Ziganshin wrote:
Hello Ashley,
Monday, August 25, 2008, 3:12:18 AM, you wrote:
Is there any interest in implementing a top level "<-" to run monadic code?
yes, definitely. as it's hard to develop "real" app w/o using global vars, h98 still remains "unreal" language
but from my POV it's important to push this feature into haskell standard
Haskell should be moving -toward- a capability-like model, not away from it.
participants (6)
-
Adrian Hey -
Ashley Yakeley -
Bulat Ziganshin -
Derek Elkins -
Edward Kmett -
John Meacham