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: John Max Skaller <skaller@o...>
Subject: Re: [Caml-list] two unrelated questions
Brian Rogoff wrote:
> On Thu, 26 Apr 2001, John Max Skaller wrote:
> > Unfortunately:
> >
> >       let f x =
> >               exception Break
> >               try ... raise Break ...
> >               with Break -> ()
> >       ;;
> >
> > is in error, because exception declarations must be at the top
> > level. 

> 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 ()

	Actually, this works too:

	let f x = 
		let module Local = struct exception Break end in
		try raise Local.Break with Local.Break -> ()

Furthermore, this doesn't work:

	let f x = 
		type integer = int
		let i:integer = 1 in ...

but this does:

	let f x = 
		let module Local = struct type integer = int end in
		let i: Local.integer = 1 in ...
		

which makes me wonder why it is necessary to wrap exception 
declarations and type aliases in modules: is there a semantic
reason I'm missing, or is it just a parsing issue?

-- 
John (Max) Skaller, mailto:skaller@maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper http://Vyper.sourceforge.net
download Interscript http://Interscript.sourceforge.net
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr