Browse thread
[Caml-list] failwith, raise and type inference
-
Paul Guyot
- Frederic van der Plancke
- Correnson_Loïc
- Nicolas Cannasse
- Luc Maranget
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Frederic van der Plancke <fvdp@d...> |
| Subject: | Re: [Caml-list] failwith, raise and type inference |
Just a small precedence bug.
failwith "The key " ^ key ^ " could not be found"
is equivalent to:
(failwith "The key ") ^ key ^ " could not be found"
and not to:
failwith ("The key " ^ key ^ " could not be found")
F.
Paul Guyot wrote:
>
> 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
-------------------
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