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.0 required=5.0 tests=AWL 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 B544BBC69 for ; Sat, 5 Jan 2008 18:17:01 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAFpKf0dT9QHmeGdsb2JhbACBV45BAQoEBg8amSs X-IronPort-AV: E=Sophos;i="4.24,248,1196636400"; d="scan'208";a="6311173" Received: from pop.bulldoghome.com (HELO bdmail1.accesst.com) ([83.245.1.230]) by mail1-smtp-roc.national.inria.fr with ESMTP; 05 Jan 2008 18:17:01 +0100 Received: from host-84-9-232-85.bulldogdsl.com ([84.9.232.85] helo=[192.168.123.191]) by bdmail1.accesst.com with esmtpa (Exim 4.50) id 1JBCai-0008C1-Ut; Sat, 05 Jan 2008 17:13:49 +0000 Message-ID: <477FBA78.8060400@ed.ac.uk> Date: Sat, 05 Jan 2008 17:12:24 +0000 From: Jeremy Yallop User-Agent: Mozilla-Thunderbird 2.0.0.6 (X11/20071009) 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: 7bit X-Spam: no; 0.00; ocamlc:01 ocamlc:01 runtime:01 segfault:01 compile-time:01 compiler:01 unify:01 wrote:01 rec:01 caml-list:01 functions:01 functions:01 marshal:01 marshal:01 annotation:02 Dario Teixeira wrote: > 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: [...] > 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) [...] > 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? One way is to use both functions in a context which requires the return types to be the same. For example, you could use both functions to create the elements of a list: let rec unpickle_doc str = let _unify_return_types _ = [unpickle_doc ""; make_doc ""] in Marshal.from_string str 0 Jeremy.