Version française
Home     About     Download     Resources     Contact us    
Browse thread
break and continue for OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Martin Jambon <martin.jambon@e...>
Subject: Re: [Caml-list] break and continue for OCaml
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