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=1.0 required=5.0 tests=AWL,SPF_FAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 9AE1ABC69 for ; Sat, 5 Jan 2008 21:13:37 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAF5zf0fAXQImh2dsb2JhbACQGAEBAQgKKZkI X-IronPort-AV: E=Sophos;i="4.24,249,1196636400"; d="scan'208";a="7469269" Received: from discorde.inria.fr ([192.93.2.38]) by mail3-smtp-sop.national.inria.fr with ESMTP; 05 Jan 2008 21:13:36 +0100 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m05KDW2a023160 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Sat, 5 Jan 2008 21:13:37 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAF5zf0dQW+UCh2dsb2JhbACQGAEBAQgKKZkI X-IronPort-AV: E=Sophos;i="4.24,249,1196636400"; d="scan'208";a="5752511" Received: from main.gmane.org (HELO ciao.gmane.org) ([80.91.229.2]) by mail2-smtp-roc.national.inria.fr with ESMTP; 05 Jan 2008 21:13:32 +0100 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1JBFOc-00021h-FW for caml-list@inria.fr; Sat, 05 Jan 2008 20:13:30 +0000 Received: from ivr94-8-88-162-26-239.fbx.proxad.net ([88.162.26.239]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 05 Jan 2008 20:13:30 +0000 Received: from li by ivr94-8-88-162-26-239.fbx.proxad.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 05 Jan 2008 20:13:30 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Zheng Li Subject: Re: Type_of? Date: Sat, 05 Jan 2008 21:33:25 +0100 Message-ID: <87sl1cvwq2.fsf@pps.jussieu.fr> References: <712252.79789.qm@web54603.mail.re2.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ivr94-8-88-162-26-239.fbx.proxad.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux) Cancel-Lock: sha1:O4PCEJ6415YeJTV2SrDCQRYAP4A= Sender: news X-Miltered: at discorde with ID 477FE4EC.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; runtime:01 segfault:01 compile-time:01 compiler:01 val:01 val:01 variants:01 ocamlc:01 inference:01 bounded:01 pps:01 pps:01 pairs:01 pairs:01 jussieu:01 Hello, Dario Teixeira writes: > 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? Do you have any restriction in bounding them as pairs? The simplest example come into my mind is like: # let produce () :'a = [`Zero; `One 1] and consume (l:'a) = ();; val produce : unit -> [> `One of int | `Zero ] list = val consume : [> `One of int | `Zero ] list -> unit = In this way, you don't have to write the variants manually, since "ocamlc -i" can inference it and the type 'a in the pairs are always bounded. HTH. -- Zheng Li http://www.pps.jussieu.fr/~li