English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2008-04-10 (07:09)
From: Jean-Christophe Filliâtre <Jean-Christophe.Filliatre@l...>
Subject: Re: [Caml-list] break and continue for OCaml
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

Said otherwise, break and continue can be simply encoded with exceptions

	  while ... do
 	      .... loop body where break is raise Break ...
	      .... and continue is raise Continue ...
	    with Continue ->
	with Break ->

and thus should be typed the same way.

Jean-Christophe Filliâtre