Version franÁaise
Home ††† About ††† Download ††† Resources ††† Contact us †††
Browse thread
[Caml-list] two unrelated questions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Rogoff <bpr@b...>
Subject: Re: [Caml-list] two unrelated questions
On Thu, 26 Apr 2001, John Max Skaller wrote:
> "JudicaŽl Courant" wrote:
> 
> > >   exception Break
> > >   try
> > >     List.iter (fun ..  -> ...  raise Break) l
> > >   with Break -> ()
> 
> Unfortunately:
> 
> 	let f x = 
> 		exception Break 
> 		try ... raise Break ...
> 		with Break -> ()
> 	;;
> 
> is in error, because exception declarations must be at the top
> level. This prevents desired localisation: this feature is not
> as good as a labelled break for this purpose.

Well, this kind of thing is what local does in SML and a few people have
asked for it before. You can use the local module feature to do the
same thing.

let f x = 
  let module Local = struct 
    exception Break
    let f () = 
    try (print_endline ("hello " ^ x); raise Break) with Break -> ()
  end in
  Local.f ()

This is a very handy feature of OCaml. 

-- Brian



-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr