From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 4A66DBC57 for ; Tue, 3 Aug 2010 17:39:33 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApACAGvVV0zZSMDdi2dsb2JhbACgERUBAQEKCwoHDwUfw3aFOQQ X-IronPort-AV: E=Sophos;i="4.55,309,1278280800"; d="scan'208";a="55061634" Received: from fmmailgate01.web.de ([217.72.192.221]) by mail3-smtp-sop.national.inria.fr with ESMTP; 03 Aug 2010 17:39:32 +0200 Received: from smtp04.web.de ( [172.20.0.225]) by fmmailgate01.web.de (Postfix) with ESMTP id 4792016562B66; Tue, 3 Aug 2010 17:39:32 +0200 (CEST) Received: from [78.43.204.177] (helo=frosties.localdomain) by smtp04.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #24) id 1OgJaW-0004ZB-00; Tue, 03 Aug 2010 17:39:32 +0200 Received: from mrvn by frosties.localdomain with local (Exim 4.72) (envelope-from ) id 1OgJaV-0008W0-QF; Tue, 03 Aug 2010 17:39:31 +0200 From: Goswin von Brederlow To: Joseph Young Cc: caml-list@inria.fr Subject: Re: [Caml-list] Conditionals based on phantom types References: Date: Tue, 03 Aug 2010 17:39:31 +0200 In-Reply-To: (Joseph Young's message of "Mon, 2 Aug 2010 09:07:04 +0200 (CEST)") Message-ID: <87vd7r4sek.fsf@frosties.localdomain> User-Agent: Gnus/5.110009 (No Gnus v0.9) XEmacs/21.4.22 (linux, no MULE) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX1+k2mf4xeADfLEY0CcDh6WZYYPqCxk8BUzSGE9+ QHh1t6B8C0p2MLl2fcTE0QB+viDaxwtLwffdGsJFMImh1rKYga JjEgj9+gs= X-Spam: no; 0.00; conditionals:01 ocaml:01 trivial:01 hypothetical:01 compiler:01 trivial:01 runtime:01 runtime:01 sig:01 val:01 val:01 struct:01 printf:01 printf:01 mfg:98 Joseph Young writes: > Hi, > Is there any way to write a conditional based on the type > information of a value? Specifically, if we use phantom types to > write a module such as No, there is no way to write a conditional based on the type information. In trivial cases the hypothetical conditional could be evaluated by the compiler but only in trivial cases. The more complex cases would require a runtime evaluation of the type and the type information simply isn't there at runtime to do this. > module Units : sig > type 'a t > val to_feet : float -> [`Feet ] t > val to_meters : float -> [`Meters] t > val add : 'a t -> 'a t -> 'a t > val print : 'a t -> unit > end = struct > type 'a t = float > let to_feet x=x > let to_meters x=x > let add x y = x +. y > let print x = Printf.printf "%f (units)" x > end;; > > is there anyway to modify the print statement to correctly denote > which units are used? > > Thanks. > > Joe Instead of a phantom type use a real type. See other mails for examples. MfG Goswin