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=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id DBB0ABC69 for ; Mon, 30 Jul 2007 06:40:46 +0200 (CEST) Received: from ipmail03.adl2.internode.on.net (ipmail03.adl2.internode.on.net [203.16.214.135]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l6U4ehkE011251 for ; Mon, 30 Jul 2007 06:40:45 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAI4HrUZ5LAMf/2dsb2JhbAAN X-IronPort-AV: E=Sophos;i="4.19,196,1183300200"; d="scan'208";a="122783251" Received: from ppp121-44-3-31.lns4.syd7.internode.on.net (HELO [192.168.1.201]) ([121.44.3.31]) by ipmail03.adl2.internode.on.net with ESMTP; 30 Jul 2007 14:10:39 +0930 Subject: Re: [Caml-list] Re: Void type? From: skaller To: Arnaud Spiwack Cc: caml-list@yquem.inria.fr In-Reply-To: <46ACF35F.5070102@lix.polytechnique.fr> References: <46AC748B.10200@lix.polytechnique.fr> <200707291216.34682.jon@ffconsultancy.com> <46AC7BB8.8050609@gmail.com> <20070729124340.GA18564@furbychan.cocan.org> <46AC8EEF.1040102@gmail.com> <20070729170216.GA8137@furbychan.cocan.org> <46ACF35F.5070102@lix.polytechnique.fr> Content-Type: text/plain Date: Mon, 30 Jul 2007 14:40:37 +1000 Message-Id: <1185770437.11618.29.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 46AD6BCB.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; 0200,:01 seq:01 iter:01 seq:01 endline:01 combinators:01 combinators:01 camlp:01 syntax:01 sourceforge:01 wrote:01 arnaud:01 exception:01 caml-list:01 functions:01 On Sun, 2007-07-29 at 22:06 +0200, Arnaud Spiwack wrote: > One reason why it might be useful, is that it gives an equivalence > between the types t -> void and t -> 'a (for any type t). Earlier > in this thread it was mentioned that these sort of functions could be a > reason to use a void type. It is used like this in Felix: type void type proc = unit -> void exception Ok let squash () : void = raise Ok let call (f:proc) : unit = try ignore(f ()) with Ok -> () let seq (fs: proc list): proc = fun () -> squash (List.iter call fs) (* example *) let x = ref 0 let f () : void = squash (incr x) let incr3 : proc = seq [f;f;f];; call incr3;; print_endline ("x=" ^ string_of_int !x);; You can write combinators such as 'cond' and 'loop' as well. The combinators are purely functional and lazy, except 'call' which forces side-effecting. The advantage is the type system prevents some accidents: let f () = incr x;; f (f ());; (* woops *) by using the fact that void has no values, to prevent using the application of a procedure as the argument of an function. Given a purely functional library .. you could probably design a purely functional camlp4/5 syntax, then you'd actually get referential transparency. -- John Skaller Felix, successor to C++: http://felix.sf.net