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_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr 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 C28F1BC6B for ; Sun, 10 Feb 2008 20:15:34 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAANbbrkdA6aa1kmdsb2JhbACQOwEBAQEHBAQJChaRb4NC X-IronPort-AV: E=Sophos;i="4.25,330,1199660400"; d="scan'208";a="22448436" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 10 Feb 2008 20:15:34 +0100 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m1AJFXqu016339 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Sun, 10 Feb 2008 20:15:34 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAANbbrkdA6aa1kmdsb2JhbACQOwEBAQEHBAQJChaRb4NC X-IronPort-AV: E=Sophos;i="4.25,330,1199660400"; d="scan'208";a="22448435" Received: from py-out-1112.google.com ([64.233.166.181]) by mail4-smtp-sop.national.inria.fr with ESMTP; 10 Feb 2008 20:15:33 +0100 Received: by py-out-1112.google.com with SMTP id u52so6444078pyb.10 for ; Sun, 10 Feb 2008 11:15:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; bh=5PGixeGwSrmIC1cdJqqP1h/F3X5MC3guSvxa9h9mXnk=; b=jFaNefIRx1zbUP+Ca6IlwpFzyDycwg5ARys8cClcavwBNKc6whIezlw5iogLUkME0eMIyPoHvf6DDZMJ1tTp3NdJ+JCd74G8xSH/43J9cDoVn/FCKiPDUKI+Z8Z0QgsnCxK9v1/Pzvp4YeyqMPXU25lLJzxtStqMez4FSr2VFgU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=uaUQAv2pr77zLxKLllSSk3aG/0Ng1DqFYmv7wyP+uMP4z1+6bV4PQnMsZD+xLF+0/vfA4ZSZTxwod8oAD9rFRhlZhyHxlMjE2E915ibXVk/KjSm+yTgKYEOLd/xU1CPFgVFg2zVE1+r8ute3eXSY8mvAAme/JMyO8HdnSFDbLg4= Received: by 10.35.69.11 with SMTP id w11mr17057668pyk.60.1202670932062; Sun, 10 Feb 2008 11:15:32 -0800 (PST) Received: from ?192.168.0.16? ( [71.149.128.127]) by mx.google.com with ESMTPS id n29sm49429555pyh.41.2008.02.10.11.15.30 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 10 Feb 2008 11:15:31 -0800 (PST) Message-ID: <47AF4D50.9070104@gmail.com> Date: Sun, 10 Feb 2008 13:15:28 -0600 From: Edgar Friendly User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 To: Dawid Toton Cc: Caml List Subject: Re: [Caml-list] Fine-grained types with more general library References: <47AF4B6E.3070306@uj.edu.pl> In-Reply-To: <47AF4B6E.3070306@uj.edu.pl> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 47AF4D55.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; fine-grained:01 val:01 val:01 edgar:98 wrote:01 caml-list:01 caml-list:01 functions:01 caml:02 string:02 string:02 library:03 library:03 types:05 types:05 Dawid Toton wrote: > I have a type (e.g. of path to file) > > type path = string list > > and many operations (e.g. path manipulation). Then I need to have two > kinds of paths (e.g. local and remote) and want type system to enforce > proper usage (some functions act on remote paths only etc.). So I create > new two types: > > type remote_t = Remote path > type local_t = Local path > > Then I avoid using type path for greater safety. But I have a problem: > can't use path manipulation library on these new types. I have created > "mirror" versions of the library for each new type, but this made my > source code unmaintainable. What is the right solution? > > I'd prefer not to contaminate the path library with things specific to > this particular problem, since it's reused. > > Dawid > type 'a path = string list type remote_t = `Remote path type local_t = `Local path val works_on_remote_t : [> `Remote] path -> whatever val works_on_local_t : [> `Local] path -> whatever val works_on_any_t : 'a path -> whatever See the following URL for more details on this trick (called Phantom Types): http://caml.inria.fr/pub/ml-archives/caml-list/2001/09/081c77179ee2a3787233902a51633122.en.html E