Date: Tue, 17 Aug 2004 11:23:03 +0900 (JST) Message-Id: <20040817.112303.63133884.garrigue at kurims.kyoto-u.ac.jp> To: seguso.forever at tin.it Cc: lablgtk at kaba.or.jp Subject: Re: Getting rid of the imperative style From: Jacques Garrigue In-Reply-To: <200408170123.20592.seguso.forever at tin.it> References: <200408170123.20592.seguso.forever at tin.it> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit From: Maurizio Colucci > Currently lablgtk (and in general any library based on callbacks) forces an > imperative style on the program. In other words, when using lablgtk you > cannot avoid using the := operator. Indeed, and the area of research in functional GUIs is an active one. The results are often not so easy to use, but the approach taken by the Clean team for instance seems promising. Note of course that you cannot get rid of state in itself: GUIs are inherently stateful. Just this state can be handled in a functional way. Compared with these still experimental GUIs, the area of callback-based GUIs is well understood, and callbacks are a very powerful mechanism in them. Note also that callbacks themselves are functions, and that (impure) functional languages are particularly adapted to this paradigm. This is why I think that this is a reasonable choice for ocaml, as long as we can limit ourselves to "needed" state, that is state intrinsic to the GUI meaning, not to its implementation. > Fortunately, there is a way to rewrite that code without :=. > The rewritten code should have an explicit main loop, that is, we don't call > Gmain.Main.main anymore. Furthermore, lablgtk should supply a primitive > function > > pending_events: () -> event list Actually, GTK itself is implemented in this way at a lower level. And it even provides functions to get an event without firing its callbacks, IIRC. So you're free to try such an approach (this would need wrapping a few more functions yet.) The main problem recognized with this approach is that you get events at a global level, for the whole application. It makes it much more difficult to build a modular application. I have a strong tendency to think that you have better use state when a purely functional approach forces you to break modularity. As stated above, there are other approaches which allow using purely functional GUI in a more modular way. This is not the goal of lablgtk itself, but one such GUI might possibly be built on top of its lower level. Jacques