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 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 77D57BBC1 for ; Thu, 10 Apr 2008 15:39:58 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AskAAMu1/UdQRFuwiGdsb2JhbACRSwEBAQ8mmTs X-IronPort-AV: E=Sophos;i="4.25,635,1199660400"; d="scan'208";a="9430829" Received: from discorde.inria.fr ([192.93.2.38]) by mail2-smtp-roc.national.inria.fr with ESMTP; 10 Apr 2008 15:39:58 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m3ADdn1t028665 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Thu, 10 Apr 2008 15:39:58 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AskAAMu1/UdQRFuwiGdsb2JhbACRSwEBAQ8mmTs X-IronPort-AV: E=Sophos;i="4.25,635,1199660400"; d="scan'208";a="9430827" Received: from furbychan.cocan.org ([80.68.91.176]) by mail2-smtp-roc.national.inria.fr with ESMTP; 10 Apr 2008 15:39:57 +0200 Received: from rich by furbychan.cocan.org with local (Exim 4.63) (envelope-from ) id 1Jjx0O-0001OP-Ou; Thu, 10 Apr 2008 14:39:56 +0100 Date: Thu, 10 Apr 2008 14:39:56 +0100 To: Sanghyeon Seo Cc: caml-list@inria.fr Subject: Re: [Caml-list] break and continue for OCaml Message-ID: <20080410133956.GA4065@annexia.org> References: <5b0248170804091859s75c3f725s2db53f48fba6735c@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5b0248170804091859s75c3f725s2db53f48fba6735c@mail.gmail.com> User-Agent: Mutt/1.5.13 (2006-08-11) From: Richard Jones X-Miltered: at discorde with ID 47FE18A5.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 type-safe:01 10,:98 seo:98 wrote:01 caml-list:01 unsafe:01 unsafe:01 len:02 string:02 string:02 let:03 let:03 raise:03 shorter:04 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 Rich. -- Richard Jones Red Hat