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: David Allsopp <dra-news@m...>
Subject: RE: [Caml-list] break and continue for OCaml
Is there therefore any reasonable performance gain over implementing
break/continue as a camlp4 extension rather than as a compiler patch?


David


Jean-Christophe Filliātre wrote:
> Sanghyeon Seo wrote:
> > I have the first cut of patch to implement break and continue inside
> > for and while loops for OCaml.
> > 
> > http://sparcs.kaist.ac.kr/~tinuviel/devel/ocaml/
> > 
> > Patch is against OCaml 3.10.2. All the meat is in bytecomp/bytegen.ml.
> > Currently bytecode only. I am working on natvie code and error
> > handling when break is used outside loop etc but I thought "releasing
> > early" could be useful.
> > 
> > What do you think?
>
> A comment on typing break and continue: If I read your patch correctly,
> you're giving type "unit" to both expressions "break" and "continue". I
> was rather expecting type 'a instead, as for "raise exn". It could be
> useful in situations like this
>
>	while ... do
>	  let x = ... [if ... then break else ...] ... in
>	  ...
>	done
>
> Said otherwise, break and continue can be simply encoded with exceptions
>
>	try
>	  while ... do
>             try
>  	      .... loop body where break is raise Break ...
>	      .... and continue is raise Continue ...
>	    with Continue ->
>               ()
>	  done
>	with Break ->
>	  ()
>
> and thus should be typed the same way.
>
> -- 
> Jean-Christophe Filliātre
> http://www.lri.fr/~filliatr/