Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Tiphaine Turpin <Tiphaine.Turpin@irisa.fr>
To: Goswin von Brederlow <goswin-v-b@web.de>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Problem correlating input and output type
Date: Sun, 31 Jan 2010 20:28:20 +0100	[thread overview]
Message-ID: <4B65D9D4.4030101@irisa.fr> (raw)
In-Reply-To: <87fx5mi25n.fsf@frosties.localdomain>

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).

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



  reply	other threads:[~2010-01-31 19:31 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 ` Tiphaine Turpin [this message]
2010-02-01 15:59   ` [Caml-list] " Goswin von Brederlow
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=4B65D9D4.4030101@irisa.fr \
    --to=tiphaine.turpin@irisa.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=goswin-v-b@web.de \
    /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