From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_WHOIS autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 2BD3FBC69 for ; Sat, 5 Jan 2008 17:41:32 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAACxCf0fOvjGtoWdsb2JhbACQGAEBAQEHBAYpmUQ X-IronPort-AV: E=Sophos;i="4.24,248,1196636400"; d="scan'208";a="6310539" Received: from web54603.mail.re2.yahoo.com ([206.190.49.173]) by mail1-smtp-roc.national.inria.fr with SMTP; 05 Jan 2008 17:41:31 +0100 Received: (qmail 81396 invoked by uid 60001); 5 Jan 2008 16:41:30 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=tAOqWpPM/oIKADDt9uq9dO/jkVhMe2ymCV6AZhneQ6E1zcnojVDVgqXiCfW0xFYXljBXf6QQS560n7Vcr3ILUdpTPEzrmcE8YucfN8tXYPiliq4FEW+qDvZW+GcT+VeYma9hew+hjEvIBHh7P0oaEWtXDxQOVz6f2ZD6tNur8DQ=; X-YMail-OSG: XbHBqn4VM1nxfrQIc790AclNcDC97JQnxP7T4Digs.RlN5.4SEQ4HM5M6yLoKzM_zIwceResj.lWi8kDTmRJsXvixsQf7e0LPW45TqPIdxXExqeoRNys9fOlSpaaviaY3cTpAzoYsXj8QFAy_sDan3scBw-- Received: from [85.244.10.148] by web54603.mail.re2.yahoo.com via HTTP; Sat, 05 Jan 2008 16:41:30 GMT Date: Sat, 5 Jan 2008 16:41:30 +0000 (GMT) From: Dario Teixeira Subject: Type_of? To: caml-list@yquem.inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <712252.79789.qm@web54603.mail.re2.yahoo.com> X-Spam: no; 0.00; variants:01 verbose:01 inference:01 ocamlc:01 val:01 elt:01 ocamlc:01 elt:01 runtime:01 segfault:01 compile-time:01 compiler:01 noscript:98 noscript:98 campaign:98 Hi, I'm using the XHTML.M module from the Ocsigen project to generate valid XHTML pages. It makes heavy use of polymorphic variants, and as such the types produced can be quite verbose and complex. In practice, however, one is rarely confronted with them (thank goodness for latent typing and type inference!). There is one exception, though: when unmarshalling, one must explicitly provide the return type. And this is the context for my question. So, imagine I have a module with only two functions. The first, "make_doc", uses XHTML.M and its signature is therefore quite complex. This is what "ocamlc -i" tells me: val make_doc: string -> [< `Address | `Blockquote | `Del | `Div | `Dl | `Fieldset | `Form | `H1 | `H2 | `H3 | `H4 | `H5 | `H6 | `Hr | `Ins | `Noscript | `Ol | `P | `PCDATA | `Pre | `Script | `Table | `Ul > `Blockquote `H1 `P ] XHTML.M.elt list The second function, "unpickle_doc", uses the Marshal module to deserialise from a string a previously pickled doc. This is the definition of this function: (note that I've used copy & paste of the previous output of "ocamlc -i" to provide the explicit type annotation) let unpickle_doc str : [< `Address | `Blockquote | `Del | `Div | `Dl | `Fieldset | `Form | `H1 | `H2 | `H3 | `H4 | `H5 | `H6 | `Hr | `Ins | `Noscript | `Ol | `P | `PCDATA | `Pre | `Script | `Table | `Ul > `Blockquote `H1 `P ] XHTML.M.elt list = Marshal.from_string str 0 Now, this works fine. It is however error prone, since if the signature of make_doc changes somewhat and I forget to update the type annotation in unpickle_doc, then I get a nasty runtime segfault. So this is my question: since the return type of make_doc is known at compile-time, is there any way I can tell the compiler that the return type of unpickle_doc should be the same as make_doc's? Thank you for your help! Dario Teixeira ___________________________________________________________ Support the World Aids Awareness campaign this month with Yahoo! For Good http://uk.promotions.yahoo.com/forgood/