From: Yoann Padioleau <padator@wanadoo.fr>
To: Caml-list List <caml-list@inria.fr>
Subject: typing problem with sexplib and mutually recursive polymorphic types
Date: Tue, 10 Mar 2009 21:45:58 -0500 [thread overview]
Message-ID: <87prgoydy1.fsf@aryx.cs.uiuc.edu> (raw)
Hi,
I tried a slightly modified version of sexplib by jane street
on this simple file foo.ml:
type 'a x1 = 'a * 'a
and x2 = int x1
and x3 = string x1
(* with sexp *)
and succeeded to generate another file containing the sexp_of_xx code
in a file foo2.ml:
open Foo
let rec x1_of_sexp__ =
let _loc = "Xxx.x1"
in
fun _of_a ->
function
| Sexp.List ([ v1; v2 ]) ->
let v1 = _of_a v1 and v2 = _of_a v2 in (v1, v2)
| sexp -> Conv_error.tuple_of_size_n_expected _loc 2 sexp
and x1_of_sexp _of_a sexp =
try x1_of_sexp__ _of_a sexp
with
| Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
and x2_of_sexp__ =
let _loc = "Xxx.x2" in fun sexp -> x1_of_sexp Conv.int_of_sexp sexp
and x2_of_sexp sexp =
try x2_of_sexp__ sexp
with
| Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
and x3_of_sexp__ =
let _loc = "Xxx.x3" in fun sexp -> x1_of_sexp Conv.string_of_sexp sexp
and x3_of_sexp sexp =
try x3_of_sexp__ sexp
with
| Conv_error.No_variant_match ((msg, sexp)) -> Conv.of_sexp_error msg sexp
let rec sexp_of_x1 _of_a (v1, v2) =
let v1 = _of_a v1 and v2 = _of_a v2 in Sexp.List [ v1; v2 ]
and sexp_of_x2 v = sexp_of_x1 Conv.sexp_of_int v
and sexp_of_x3 v = sexp_of_x1 Conv.sexp_of_string v
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 ?
next reply other threads:[~2009-03-11 2:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-11 2:45 Yoann Padioleau [this message]
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
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=87prgoydy1.fsf@aryx.cs.uiuc.edu \
--to=padator@wanadoo.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