caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Teller <David.Teller@univ-orleans.fr>
To: Christophe TROESTLER <Christophe.Troestler+ocaml@umh.ac.be>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Polymorphic variant as a witness?
Date: Sun, 22 Jun 2008 01:52:11 +0200	[thread overview]
Message-ID: <1214092331.6190.31.camel@Blefuscu> (raw)
In-Reply-To: <20080622.012752.1098181329612502108.Christophe.Troestler+ocaml@umh.ac.be>


On Sun, 2008-06-22 at 01:27 +0200, Christophe TROESTLER wrote:
> On Sun, 22 Jun 2008 01:11:59 +0200, David Teller wrote:
> > 
> > I could have a value (let's call it "witness") with type 
> >   [> ] ref
> 
> Why do you want it to be mutable?

Because I know how to change the type of a reference to a polymorphic
variant (the touching) -- but not the type of an immutable polymorphic
variant.

> > which I could "touch" into becoming 
> >   [> `A] ref
> 
> Are you expecting to write [touch `A witness] so [witness] becomes of
> type [[> `A] ref]?  If you can do with an immutable [witness], then
> you can write a macro to that effet (use: [let witness' = TOUCH `A
> witness]).  What exactly is your purpose?

Say you are developing a Camlp4-based DSL in which
* file access may only be performed by some construction -- let's call
it FILE
* network access may only be performed by some construction -- let's
call it NET.

I'd like to take advantage of OCaml's type system to tell me if file
access and/or network access have taken place. Now, since I'm
implementing FILE and NET from within Camlp4, I can give them whichever
semantics I want. For instance, FILE could mean [touch `File witness;
foo] and NET could mean [touch `Net witness; bar]. If I write a program
containing FILE, OCaml's type system will have inferred that the type of
[witness] is [[> `File]]. Which would be great for me.

Now I know I could do that with monads. I could also implement a type
system for the DSL. I'm just wondering if polymorphic variants could
provide an alternative. Because if they can, it may have direct
applications to exception management for OCaml.


> Regards,
> C.

Cheers,
 David

-- 
David Teller
 Security of Distributed Systems
  http://www.univ-orleans.fr/lifo/Members/David.Teller
 Angry researcher: French Universities need reforms, but the LRU act brings liquidations. 


  reply	other threads:[~2008-06-21 23:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-21 23:11 David Teller
2008-06-21 23:27 ` [Caml-list] " Christophe TROESTLER
2008-06-21 23:52   ` David Teller [this message]
2008-06-23  8:13 ` Romain Bardou
2008-06-23 10:27 ` Jacques Garrigue
2008-06-27  6:00   ` David Teller
2008-06-27  6:38     ` Jacques Garrigue
2008-07-04 13:05 ` Polymorphic variant + phantom type as a witness Gleb Alexeyev

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=1214092331.6190.31.camel@Blefuscu \
    --to=david.teller@univ-orleans.fr \
    --cc=Christophe.Troestler+ocaml@umh.ac.be \
    --cc=caml-list@inria.fr \
    /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).