From: Gleb Alexeyev <gleb.alexeev@gmail.com>
To: caml-list@inria.fr
Subject: Re: Polymorphic variant + phantom type as a witness
Date: Fri, 04 Jul 2008 16:05:20 +0300 [thread overview]
Message-ID: <g4l76g$mbe$1@ger.gmane.org> (raw)
In-Reply-To: <1214089919.6190.13.camel@Blefuscu>
I've been pondering about something along these lines (if I understand
it correctly, it seems to resemble what Jacques Garrigue proposed -
passing a witness as extra argument to every effectful function).
I didn't think it through and haven't use it in practice, so I don't
know whether it's usable, but anyway:
module type Permission = sig
type 'a t
end
module Permission : Permission = struct
type 'a t = unit
(* here we need some means to cook new permissions - this is the part
I didn't think through *)
end
module type SafeEffect = sig
(* signatures of effectful primitives to be used instead of functions
from Pervasives *)
val print : [> `IO] Permission.t -> string -> unit
val setref : [> `State] Permission.t -> 'a ref -> 'a -> unit
end
module SafeEffect : SafeEffect = struct
(* implementation ignores the witness *)
let print _ s = print_endline s
let setref _ r x = r := x
end
module Example = struct
module S = SafeEffect
let use_io effect () = (S.print effect "bar"; 42)
let global_n = ref 0
let use_state effect () =
S.setref effect global_n 42
let use_both effect () =
use_io effect ();
use_state effect ()
end
The inferred signatures expose the effects:
val use_io : [> `IO ] Permission.t -> unit -> int
val use_state : [> `State ] Permission.t -> unit -> unit
val use_both : [> `IO | `State ] Permission.t -> unit -> unit
prev parent reply other threads:[~2008-07-04 13:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-21 23:11 Polymorphic variant as a witness? David Teller
2008-06-21 23:27 ` [Caml-list] " Christophe TROESTLER
2008-06-21 23:52 ` David Teller
2008-06-23 8:13 ` Romain Bardou
2008-06-23 10:27 ` Jacques Garrigue
2008-06-27 6:00 ` David Teller
2008-06-27 6:38 ` Jacques Garrigue
2008-07-04 13:05 ` Gleb Alexeyev [this message]
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='g4l76g$mbe$1@ger.gmane.org' \
--to=gleb.alexeev@gmail.com \
--cc=caml-list@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;
as well as URLs for NNTP newsgroup(s).