caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] failwith, raise and type inference
@ 2004-04-02 13:41 Paul Guyot
  2004-04-02 13:49 ` Frederic van der Plancke
                   ` (3 more replies)
  0 siblings, 4 replies; 24+ messages in thread
From: Paul Guyot @ 2004-04-02 13:41 UTC (permalink / raw)
  To: caml-list

Hello,

My students came up with a behavior of ocaml I couldn't explain.
I have exactly the same result with 3.07pl2 and a fresh copy checked 
out from CVS.

>let rec f1 key dict =
>	match dict with
>		[] -> failwith "The key " ^ key ^ " could not be found"
>		| (aKey, aValue)::tail ->
>			if (aKey = key)
>			then aValue
>			else f1 key tail;;

is of type:

val f1 : string -> (string * string) list -> string = <fun>

while:

>exception SomeException of string;;
>
>let rec f2 key dict =
>	match dict with
>		[] -> raise (SomeException key)
>		| (aKey, aValue)::tail ->
>			if (aKey = key)
>			then aValue
>			else f2 key tail;;

is of type:

val f2 : string -> (string * 'a) list -> 'a = <fun>

Considering that failwith is of type string -> 'a and raise of type 
exn -> 'a, I couldn't figure out why the correct type for f is only 
infered with raise.

Any idea?

Paul
-- 
Philosophie de baignoire - consultations sur rendez-vous.

NPDS/NewtonOS: http://newton.kallisys.net:8080/
Apache/FreeBSD: http://www.kallisys.com/

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2004-04-09  8:03 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-02 13:41 [Caml-list] failwith, raise and type inference Paul Guyot
2004-04-02 13:49 ` Frederic van der Plancke
2004-04-02 13:56   ` Paul Guyot
2004-04-02 13:51 ` Nicolas Cannasse
2004-04-02 13:59 ` Correnson Loïc
2004-04-02 14:09 ` Luc Maranget
2004-04-02 19:39   ` [Caml-list] weird floating poing behavior on windows Zeno Lee
2004-04-02 20:03     ` Greg Bacon
2004-04-02 20:07     ` David Brown
2004-04-02 20:31       ` Zeno Lee
2004-04-02 20:50         ` Pierre Weis
2004-04-02 22:01         ` Brian Hurt
2004-04-02 21:58     ` Brian Hurt
2004-04-02 20:28   ` [Caml-list] failwith, raise and type inference Pierre Weis
2004-04-05 22:52     ` Ker Lutyn
2004-04-06  1:07       ` Jacques Garrigue
2004-04-06  5:23         ` Issac Trotts
2004-04-06 15:15           ` skaller
2004-04-06  1:15       ` Christophe TROESTLER
2004-04-06  7:05         ` skaller
2004-04-06 11:29           ` Eric C. Cooper
2004-04-09  7:18           ` Christophe TROESTLER
2004-04-09  7:32             ` Xavier Leroy
2004-04-09  8:03               ` skaller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).