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 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 1037BBBC1 for ; Thu, 10 Apr 2008 16:07:17 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAOO7/UfAXQIn/2dsb2JhbACrTQ X-IronPort-AV: E=Sophos;i="4.25,636,1199660400"; d="scan'208";a="11304760" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 10 Apr 2008 16:07:16 +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 m3AE7Dfe004222 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 10 Apr 2008 16:07:16 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al0AAE67/UdCbwQck2dsb2JhbACRSgEBAQEJAwkJFplH X-IronPort-AV: E=Sophos;i="4.25,635,1199660400"; d="scan'208";a="24845151" Received: from out4.smtp.messagingengine.com ([66.111.4.28]) by mail4-smtp-sop.national.inria.fr with ESMTP; 10 Apr 2008 16:07:13 +0200 Received: from compute1.internal (compute1.internal [10.202.2.41]) by out1.messagingengine.com (Postfix) with ESMTP id E4DFCED884; Thu, 10 Apr 2008 10:07:12 -0400 (EDT) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute1.internal (MEProxy); Thu, 10 Apr 2008 10:07:12 -0400 X-Sasl-enc: 2Q7bHfThk1CgLEH1GWy+YiXHL76jHAKgbg28mjzal3mA 1207836431 Received: from [192.168.1.10] (ALyon-157-1-61-61.w81-251.abo.wanadoo.fr [81.251.28.61]) by mail.messagingengine.com (Postfix) with ESMTPSA id 1B4A114514; Thu, 10 Apr 2008 10:07:10 -0400 (EDT) Date: Thu, 10 Apr 2008 16:05:45 +0200 (CEST) From: Martin Jambon X-X-Sender: martin@martin.ec.wink.com To: Richard Jones Cc: Sanghyeon Seo , caml-list@inria.fr Subject: Re: [Caml-list] break and continue for OCaml In-Reply-To: <20080410133956.GA4065@annexia.org> Message-ID: References: <5b0248170804091859s75c3f725s2db53f48fba6735c@mail.gmail.com> <20080410133956.GA4065@annexia.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at concorde with ID 47FE1F11.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ens-lyon:01 ocaml:01 type-safe:01 struct:01 10,:98 seo:98 wrote:01 wrote:01 caml-list:01 unsafe:01 unsafe:01 jambon:01 jambon:01 lazy:02 lazy:02 On Thu, 10 Apr 2008, Richard Jones wrote: > On Thu, Apr 10, 2008 at 10:59:16AM +0900, Sanghyeon Seo wrote: >> What do you think? > > When you've done that, how about a type-safe return statement? It > should immediately return from the inner-most function, allowing one > to return a value. > > Here's a usage scenario (modified from Extlib, it would be even > shorter with 'break'): > > (* Find the index of string 'sub' within 'str' *) > let find str sub = > let sublen = String.length sub in > if sublen = 0 then return 0; > > let len = String.length str in > for i = 0 to len-sublen do > let j = ref 0 in > while String.unsafe_get str (i + !j) = String.unsafe_get sub !j do > incr j; > if !j = sublen then return i > done; > done; > raise Not_found I'm OK with the intent, but what should happen in such cases: module A = struct let a = break let b = continue let c = return true let d = lazy (return 123) let e () = Lazy.force d end Martin -- http://wink.com/profile/mjambon http://mjambon.com