caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <markus.mottl@gmail.com>
To: Yoann Padioleau <padator@wanadoo.fr>
Cc: 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 00:25:00 -0400	[thread overview]
Message-ID: <f8560b80903102125h784906d3ged83273e5cf523b0@mail.gmail.com> (raw)
In-Reply-To: <87prgoydy1.fsf@aryx.cs.uiuc.edu>

On Tue, Mar 10, 2009 at 22:45, Yoann Padioleau <padator@wanadoo.fr> wrote:
> But then the ocaml type system refuses to type this second file with the
> error message:
> File "foo2.ml", line 22, characters 48-67:
> This expression has type Sexp.t -> string but is here used with type
>  Sexp.t -> int
>
> Apparently the problem is that ocaml was not able to generalize
> the type of x1_of_sexp and that it's first utilisation with an 'int'
> force the x1_of_sexp to always return an 'int' instead of a 'string'
> in the second case. Is there a way to rewrite this generated code
> to avoid this typing problem ? Is it because of those
>  'let _loc = ... in fun ... ->"  that distrubs the ocaml type system ?

This has to do with recursive type definitions, not with generating
closures with _loc.  The following is similar and does not compile
either:

  let rec foo () = []
  and bar () = "asdf" :: foo ()
  and bla () = 42 :: foo ()

These definitions are clearly sound, but the type checker doesn't get
it.  Note, however, that the following works:

  let foo () = []
  let rec bar () = "asdf" :: foo ()
  and bla () = 42 :: foo ()

You can apply the same trick in your specific example by simply moving
the type definition of x1 out of the cycle with x2 and x3.

Cheers,
Markus

-- 
Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com


  reply	other threads:[~2009-03-11  4:25 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 ` Markus Mottl [this message]
2009-03-11  6:11   ` [Caml-list] " 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
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=f8560b80903102125h784906d3ged83273e5cf523b0@mail.gmail.com \
    --to=markus.mottl@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=padator@wanadoo.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).