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.9 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id A9DBCBC69 for ; Sat, 5 Jan 2008 18:44:03 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FACpRf0dIDvyaY2dsb2JhbACQDhQFBSOTW4VR X-IronPort-AV: E=Sophos;i="4.24,248,1196636400"; d="scan'208";a="20929866" Received: from po-out-1718.google.com ([72.14.252.154]) by mail4-smtp-sop.national.inria.fr with ESMTP; 05 Jan 2008 18:44:02 +0100 Received: by po-out-1718.google.com with SMTP id b23so182120poe.3 for ; Sat, 05 Jan 2008 09:44:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; bh=oSZ77GnfUyAZYsBD5ypvpF/y6doDnkXzhdxLd3hzbxM=; b=Hm4lZyNuc9BuYt0ZlsRu+TcM/wvQFcBMhTQdhlx3ZeJ+ebpBA0OXd9uufh7VHEGSERkoj/HbmCxK1UKZqDB1hgC9i/iUqTzSufIOFn1mF9R5iJhiJM4FnyMEW/akkdndIKWsiKQiBvJTOUCW8vEIL8JKy+YLmq6P0TFPDcTItEs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=FIgqOBFEIZiqGn9elAF3UM/W0TNFBuU4LqugiCqrIEPxiD8QYeRjuSTgAdacEX0VDdc1+F62OKIg0YSdONKGVXxDYZZdmioj/GrmJ0s/TLek0W5znSUp+37CoY0S6Ji7V+z28BBXeRm6yEKBSQyR/lLy4vFxvod8tKTdnYPamsQ= Received: by 10.141.129.14 with SMTP id g14mr9585717rvn.274.1199555041510; Sat, 05 Jan 2008 09:44:01 -0800 (PST) Received: from ?192.168.0.3? ( [87.88.165.197]) by mx.google.com with ESMTPS id s8sm18619552uge.3.2008.01.05.09.43.59 (version=SSLv3 cipher=RC4-MD5); Sat, 05 Jan 2008 09:44:00 -0800 (PST) Message-ID: <477FC1DC.701@lix.polytechnique.fr> Date: Sat, 05 Jan 2008 18:43:56 +0100 From: Arnaud Spiwack User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: Dario Teixeira Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Type_of? References: <712252.79789.qm@web54603.mail.re2.yahoo.com> In-Reply-To: <712252.79789.qm@web54603.mail.re2.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Sender: Arnaud Spiwack X-Spam: no; 0.00; lix:01 elt:01 syntax:01 variants:01 verbose:01 inference:01 ocamlc:01 val:01 elt:01 ocamlc:01 runtime:01 segfault:01 compile-time:01 compiler:01 beginner's:01 Hello, How about giving it a name ? For instance: type 'a make_doc_type = 'a XHTML.M.elt list constraint 'a = [< `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 ] (this is untested, might contain a few dozens syntax errors, but it's the idea). Arnaud Spiwack Dario Teixeira a écrit : > 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/ > > _______________________________________________ > 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 > >