On 2009-03-11, at 15:44, Markus Mottl wrote:

That's true, but unlike Haskell OCaml doesn't have mandatory types.
This means the user can't force the compiler to start out with
user-provided type declarations.  The OCaml compiler will always run
type inference first and only try to unify the result with the
user-provided type declaration, i.e. when it's too late.

That is not quite true any more.  For example, I changed the
type-checker a few years ago to start with the user-provided type
when typing a let rec, in order to be able to debug my large
recursive definitions.  Note that I didn't do that from scrach,
I used an infrastructure that was already present for seeding the
type inference in some cases.  IIRC, it is there for some object-
oriented reason.

Next time you have a type error on the wrong recursive call, try
annotating the function at its definition point.

For example, compare the error messages for:

  let rec f x = g x []
  and g x l =
    match l with
    | [] -> f "a"
    | [a] -> f 1
    | [a; b] -> f 2
    | _ -> f 3
  ;;

versus:

  let rec f (x : int) = g x []
  and g x l =
    match l with
    | [] -> f "a"
    | [a] -> f 1
    | [a; b] -> f 2
    | _ -> f 3
  ;;

Note that your second sentence is still right, because type annotations
are only used in this way in a limited number of cases (let rec is one
example).

-- Damien

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to