From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id E4AFCBB84 for ; Fri, 4 Jul 2008 15:05:41 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApsEAKC8bUjAXQIn/2dsb2JhbACKfqV6 X-IronPort-AV: E=Sophos;i="4.30,302,1212357600"; d="scan'208";a="12823421" Received: from concorde.inria.fr ([192.93.2.39]) by mail2-smtp-roc.national.inria.fr with ESMTP; 04 Jul 2008 15:05:41 +0200 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m64D5c72004886 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 4 Jul 2008 15:05:41 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtwCAFm9bUhQW+UCgWdsb2JhbACKfodXAQEQIASdZA X-IronPort-AV: E=Sophos;i="4.30,302,1212357600"; d="scan'208";a="27019854" Received: from main.gmane.org (HELO ciao.gmane.org) ([80.91.229.2]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 04 Jul 2008 15:05:34 +0200 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1KEkyf-00063Q-3F for caml-list@inria.fr; Fri, 04 Jul 2008 13:05:29 +0000 Received: from skuns.zoral.com.ua ([91.193.166.194]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 04 Jul 2008 13:05:29 +0000 Received: from gleb.alexeev by skuns.zoral.com.ua with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 04 Jul 2008 13:05:29 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Gleb Alexeyev Subject: Re: Polymorphic variant + phantom type as a witness Date: Fri, 04 Jul 2008 16:05:20 +0300 Message-ID: References: <1214089919.6190.13.camel@Blefuscu> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: skuns.zoral.com.ua User-Agent: Thunderbird 2.0.0.14 (X11/20080502) In-Reply-To: <1214089919.6190.13.camel@Blefuscu> Sender: news X-Miltered: at concorde with ID 486E2022.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; sig:01 struct:01 sig:01 pervasives:01 val:01 val:01 struct:01 endline:01 polymorphic:01 signatures:01 signatures:01 functions:01 int:01 primitives:01 variant:02 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