From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 E8444BC57 for ; Mon, 2 Aug 2010 09:49:46 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am0DABwVVkzRVdS2kGdsb2JhbACgCQgVAQEBAQkJDAcRAx+lQYkEghCFIS6IVAEBAwWFNASIf4JL X-IronPort-AV: E=Sophos;i="4.55,302,1278280800"; d="scan'208";a="67196221" Received: from mail-px0-f182.google.com ([209.85.212.182]) by mail4-smtp-sop.national.inria.fr with ESMTP; 02 Aug 2010 09:49:46 +0200 Received: by pxi8 with SMTP id 8so1781759pxi.27 for ; Mon, 02 Aug 2010 00:49:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=rZOygP5hDeeTL8RqS4EAYFsvDCtc2LbfhamXOHYHv3A=; b=aXniaIpithYZERC1I9s8pXMOWsJszvL8CfZHUF9xune2evpqb0zOtZ6rMbYOUoFdI7 MXuvGXMGfA40y8IzLC971E5P+AqrvxOVh6By5Xwvtfa0Zj6QaZ6mqyoNoY/aSeYH6s7y /OLPRY0gy408+bx/RouEZ6E3AGKkHWud9lZ90= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=OVLtAFtT75nqreMJZa50pOMuR1rYFgkigwil36iEerHTucwrzA9Lu+k0GWoLZCelpm oyIwocEQPUHvOfksldEpVMcfFP+nPDChJUzBNg+oSypFSMmJ6GKo1YJFH6TUHUYpIMGH BAlpYbCbvqGkPdOwokOH0KtSwhN4Dtdjvt4NA= MIME-Version: 1.0 Received: by 10.143.41.17 with SMTP id t17mr5065022wfj.315.1280735384710; Mon, 02 Aug 2010 00:49:44 -0700 (PDT) Received: by 10.142.127.7 with HTTP; Mon, 2 Aug 2010 00:49:44 -0700 (PDT) In-Reply-To: References: Date: Mon, 2 Aug 2010 09:49:44 +0200 Message-ID: Subject: Re: [Caml-list] Conditionals based on phantom types From: Lukasz Stafiniak To: Joseph Young Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; conditionals:01 lukasz:01 sig:01 val:01 val:01 struct:01 printf:01 printf:01 ocaml:01 sig:01 wrote:01 caml-list:01 floats:02 string:02 module:03 You can index values by types, i.e. store the units with the floats in the values. Otherwise, types are erased and not accessible. 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 =3D struct type 'a t =3D 'a * float let to_feet x=3D `Feet, x let to_meters x=3D `Meters, x let add (_,x) (_,y) =3D x +. y let print (u,x) =3D Printf.printf "%f %s" x (to_string u) end;; On Mon, Aug 2, 2010 at 9:07 AM, Joseph Young wrote: > Hi, > =A0 =A0 =A0 =A0Is there any way to write a conditional based on the type = information > of a value? =A0Specifically, if we use phantom types to write a module su= ch as > > module Units : sig [...]