caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Edgar Friendly <thelema314@gmail.com>
To: Dawid Toton <dawid.toton@uj.edu.pl>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Fine-grained types with more general library
Date: Sun, 10 Feb 2008 13:15:28 -0600	[thread overview]
Message-ID: <47AF4D50.9070104@gmail.com> (raw)
In-Reply-To: <47AF4B6E.3070306@uj.edu.pl>

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


  reply	other threads:[~2008-02-10 19:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-10 19:07 Dawid Toton
2008-02-10 19:15 ` Edgar Friendly [this message]
2008-02-10 19:20   ` [Caml-list] " Bünzli Daniel
2008-02-10 19:56   ` Dawid Toton
2008-02-10 19:22 ` David Teller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47AF4D50.9070104@gmail.com \
    --to=thelema314@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=dawid.toton@uj.edu.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).