Version française
Home     About     Download     Resources     Contact us    
Browse thread
OO design
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Geoffrey Alan Washburn <geoffw@c...>
Subject: Re: OO design
Jacques Garrigue wrote:
> From: Dan Grossman
> 
>> A monadic approach (where each
>> operation would return a "new" file) or linearity appears necessary for
>> the latter.
> 
> And you can perfectly encode the monadic approach in ocaml.
> In our case, we need the type of the monad to keep information about
> open and closed files.
> I include such a solution, which ensures the safety of file accesses,
> at the end of this post. Note that file handles are indexed
> statically, but you can use as many as you wish.
> 
> It should be safe with references (there is no file handle that you
> can keep around, everything stays in the monad.) But beware of fancy
> extensions, like continuations, that would allow you to capture your
> environement, included files that were open when you created the
> continuation...

	Ah, good point.  I hadn't been thinking about it quite correctly when I 
was doing the thought experiment, but a simpler way to look at it is 
that "the IO monad and the (implicit) state monad commute".  Therefore, 
mutable references won't actually cause a problem.