caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Damien Doligez <damien.doligez@inria.fr>
To: Caml-list List <caml-list@inria.fr>
Subject: Re: [Caml-list] typing problem with sexplib and mutually recursive  polymorphic types
Date: Wed, 11 Mar 2009 17:16:36 +0100	[thread overview]
Message-ID: <D7B79848-190B-4FCC-885C-241AB2013066@inria.fr> (raw)
In-Reply-To: <f8560b80903110744v193bd3em905a47b59686eac0@mail.gmail.com>


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


  reply	other threads:[~2009-03-11 16:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-11  2:45 Yoann Padioleau
2009-03-11  4:25 ` [Caml-list] " Markus Mottl
2009-03-11  6:11   ` yoann padioleau
2009-03-11 14:20     ` Markus Mottl
2009-03-11 14:32       ` Yitzhak Mandelbaum
2009-03-11 14:44         ` Markus Mottl
2009-03-11 16:16           ` Damien Doligez [this message]
2009-03-11 16:43             ` Markus Mottl
2009-03-11 19:03               ` Till Varoquaux
2009-03-12  1:42               ` Jacques Garrigue
2009-03-11 23:08         ` Yoann Padioleau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D7B79848-190B-4FCC-885C-241AB2013066@inria.fr \
    --to=damien.doligez@inria.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).