From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 79B2ABC57 for ; Mon, 2 Aug 2010 09:31:00 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As4AAE4RVkxCbwQZkWdsb2JhbACTNgEBjFkVAQEBAQkLCgcRBB6+ewWFOQ X-IronPort-AV: E=Sophos;i="4.55,301,1278280800"; d="scan'208";a="64933382" Received: from out1.smtp.messagingengine.com ([66.111.4.25]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 02 Aug 2010 09:31:00 +0200 Received: from compute1.internal (compute1.internal [10.202.2.41]) by gateway1.messagingengine.com (Postfix) with ESMTP id 59878174486 for ; Mon, 2 Aug 2010 03:30:58 -0400 (EDT) Received: from heartbeat1.messagingengine.com ([10.202.2.160]) by compute1.internal (MEProxy); Mon, 02 Aug 2010 03:30:58 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=messagingengine.com; h=date:from:to:subject:message-id:mime-version:content-type; s=smtpout; bh=gQuwcWZR8qz4xAmYyeov2ce3zRg=; b=NZ+3um0++4UMMW3vck9SEc+w0ps5PzuRw0xLBePZDIdzJ44gDJp3kZ/0Dem+mrbkV3Xhwo4v3GXx0fmNlv659eeB0/PPmvbpboMg0YYx5hrE1t2q+i2MOSggS+K/R/IGG4mTAnuN4xyPVJ/4UHpuljziUkQ5olnu1NlTCwBKD6Y= X-Sasl-enc: E+7ToZ45lppdDxNqeSqy1Obe9n8GhTVnikYYmrUvHq9F 1280734257 Received: from [192.168.0.2] (69.49.171.211.swcp.com [69.49.171.211]) by mail.messagingengine.com (Postfix) with ESMTPSA id A4E584AE3E1 for ; Mon, 2 Aug 2010 03:30:57 -0400 (EDT) Date: Mon, 2 Aug 2010 09:07:04 +0200 (CEST) From: Joseph Young X-X-Sender: josyoun@myhome To: caml-list@inria.fr Subject: Conditionals based on phantom types Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Spam: no; 0.00; ocaml:01 conditionals:01 sig:01 val:01 val:01 struct:01 printf:01 printf:01 module:03 module:03 float:03 float:03 unit:03 let:03 let:03 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 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