From: Goswin von Brederlow <goswin-v-b@web.de>
To: Tiphaine Turpin <Tiphaine.Turpin@irisa.fr>
Cc: Goswin von Brederlow <goswin-v-b@web.de>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Problem correlating input and output type
Date: Mon, 01 Feb 2010 16:59:59 +0100 [thread overview]
Message-ID: <87mxzt54lc.fsf@frosties.localdomain> (raw)
In-Reply-To: <4B65D9D4.4030101@irisa.fr> (Tiphaine Turpin's message of "Sun, 31 Jan 2010 20:28:20 +0100")
Tiphaine Turpin <Tiphaine.Turpin@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
next prev parent reply other threads:[~2010-02-01 16:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-31 18:01 Goswin von Brederlow
2010-01-31 19:28 ` [Caml-list] " Tiphaine Turpin
2010-02-01 15:59 ` Goswin von Brederlow [this message]
2010-02-01 22:12 ` Tiphaine Turpin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mxzt54lc.fsf@frosties.localdomain \
--to=goswin-v-b@web.de \
--cc=Tiphaine.Turpin@irisa.fr \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox