Tiphaine Turpin <tiphaine.tur...@irisa.fr> writes:

> Goswin von Brederlow a écrit :
>> Hi,
>>
>> last night I had a crazy idea
> Definitely :-).
>
>> [...]
>>
>>
>> Can anyone think of a way to express this so that the type system keeps
>> track of which callbacks are already connected?
>>   
> Here is an attempt (with only two "events"). Note that :
> - the imperative version cannot prevent connecting a signal more than once
> - such types can only represent sets of "parallel" edges of a lattice,
> i.e., this doesn't generalises to arbitrary "typestate" properties
> - this is just a curiosity, and not a reasonable way of doing such
> things. Runtime checking would be much easier (but still a bit hackish).

But runtime checks will only show the error when the GUI object is
instantiated. Some obscure dialog might not pop up in month.

> Tiphaine
>
> module LatticeFun : sig
>
>   type ('foo, 'bar) r
>   type t and f
>
>   val make : unit -> (f, f) r
>   val set_foo : (f, 'bar) r -> (t, 'bar) r
>   val set_bar : ('foo, f) r -> ('foo, t) r
>   val use : (t, t) r -> unit
>
> end = struct
>
>   type ('foo, 'bar) r = {foo : bool ; bar : bool}
>
>   type t
>   type f = t
>
>   let make () = {foo = false ; bar = false}
>   let set_foo x = {x with foo = true}
>   let set_bar x = {x with bar = true}
>   let use _ = ()
>
> end
>
> module LatticeImp : sig
>
>   type ('foo, 'bar) r
>   type t and f
>
>   val make : unit -> (f, f) r
>   val set_foo : ('foo, 'bar) r -> (t, 'bar) r
>   val set_bar : ('foo, 'bar) r -> ('foo, t) r
>   val use : (t, t) r -> unit
>
> end = struct
>
>   (* for some reason, the direct declaration causes a module type error *)
>   type r1 = {mutable foo : bool ; mutable bar : bool}
>   type ('foo, 'bar) r = r1
>
>   type t
>   type f = t
>
>   let make () = {foo = false ; bar = false}
>   let set_foo x = x.foo <- true ; x
>   let set_bar x = x.bar <- true ; x
>   let use _ = ()
>
> end

Thanks. That solves the first problem. But how do you translate that
into ocaml objects?

type need_click
type have_click

class type ['click] clickable_type = object
  method set_click : ...?
  method use : ...?
end

I believe a method can not change the type of a class nor can it require
the parametereized class to be of a certain type. And if I write helper
function outside the class like

let set_foo x = x#foo <- true ; x

then I can't use inheritance for them. Maybe I can use inheritance
for the class objects and module inclusion for the set_* helpers. But
how do I write the use function so that one can not use of an inherited
class?

Or how do I specify

method add_connected_obj : (<connected>) obj

The <connected> would need to be specific to the exact type of object
being added. I do believe I need something that simplifies the type with
each aplication of a callback so that all fully connected objects will
have the same basic type, e.g.

unit need_click need_drag obj => unit need_click obj => unit obj

MfG
        Goswin

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to