[Haskell-cafe] the Haskell "with" "pattern"?
jonathanccast at fastmail.fm
Wed Aug 6 12:32:41 EDT 2008
On Wed, 2008-08-06 at 18:21 +0200, Johan Tibell wrote:
> On Wed, Aug 6, 2008 at 5:44 PM, Jules Bean <jules at jellybean.co.uk> wrote:
> > Johan Tibell wrote:
> >> You probably knew this already but there's nothing in the "with idiom"
> >> that prevents the resource to escape.
> > And, it doesn't always matter. Some withs are more unsafe that others :)
> > if the 'with' constructs a nice ordinary heap allocated haskell structure
> > from the external resource then it may not matter one jot if it escapes: it
> > may be out-of-date, perhaps, but still a useful data value.
> I'm sure you're right but at the moment I can't really think of any
> such structure. Perhaps you could give an example? Why would you need
> the "with" in the first place for such a structure?
withMVar :: MVar a -> (a -> IO b) -> IO b
(useful for synchronization, among other things).
modifyMVar :: MVar a -> (a -> IO (a, b)) -> IO b
although that isn't quite within the boundaries of what `bracket' can
More information about the Haskell-Cafe