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
[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: 2001-04-26 (01:13)
From: Jacques Garrigue <garrigue@k...>
Subject: Re: [Caml-list] two unrelated questions
From: Chris Hecker <checker@d6.com>

> 1.  What is the right "functional pattern" for early-outing on success
>     while using an iter/map/fold type function?  Say I'm using iter to
>     search for something in an opaque datastructure.  Should I throw
>     an exception to get out, or is that bad style?  I guess this
>     question only makes sense for iter, since map/fold produce results
>     that you theoretically want to preserve.  So, the question is
>     really, given an iter-style interface to a datastructure (one that
>     takes an ('a -> unit)), how do you tell it to stop iterating?  I
>     guess if the function was ('a -> bool) you could do it that way,
>     but most iters aren't ((List|Array|Hashtbl).iter, for example).
>     Is throwing an exception the best bet?

How to escape with an exception is described in section 8 of the
caml-light tutorial: http://caml.inria.fr/tutorial/index.html.
So I suppose this can be described as good style.
Particularly you can see in section 8.3 how to escape with a return
value, which is a natural thing to do in a search algorithm, and is a
bit nicer than using a reference cell.


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