Hello, It's nice to see someone else is seriously thinking about this and I can't see anything obviously wrong with this on first inspection so by all means add it to the wiki. I have a few issues with it on aesthetic grounds though. There also seems to be a bit of problem with using this solution in practice (I'll mention this at the end).
Judah Jacobson wrote:
In contrast to recent proposals, this one requires no extra syntax or use of unsafe functions by the programmer.
I'm not aware of any proposals (recent or ancient:-) that require the use of unsafe functions by the programmer (well apart from the unsafePerformIO hack itself). Also adding extra syntax is no problem these days. It's trivially simple (and indeed desirable in this case IMHO). It's the underlying compiler magic requires significant extra work I think.
------------------------------------------------ Under this proposal, we would write instead: ------------------------------------------------ newtype UniqueRef = UniqueRef (IORef Integer) deriving OnceIO instance OnceInit UniqueRef where onceInit = liftM UniqueRef (newIORef 0)
A purely aesthetic objection, but to me it looks quite obfuscated compared to: uniqueRef :: IORef Integer uniqueRef <- ACIO.newIORef 0 But I guess perhaps what's going on here could be made clearer with the right syntactic sugar :-) Finally, the useage problem I mentioned. Having to create a distinct type for each "top level thing with identity" (my terminology) seems like it could cause difficulties (probably not insoluble problems though). If you look at the wiki page you'll see the device driver example I put there. This has two device handles at the top level (both same type), with a device driver API that takes either the device handle itself or a device session handle (which will contain the corresponding device handle) as parameters (so in principle it can be used with any number of devices provided the corresponding device handles are available). My question is, what would this example look like using the solution you propose? I can think of at least two possibilities, both of which seem quite awkward. But I'll leave it to you to think about this with a bit more care than perhaps I have. It'd be nice to see the solution on the Wiki too. Regards -- Adrian Hey _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe