caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Florian Hars <hars@bik-gmbh.de>
To: Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Getting rid of impossible polymorphic variant tags from infered types
Date: Wed, 03 Mar 2004 11:27:27 +0100	[thread overview]
Message-ID: <4045B30F.9000603@bik-gmbh.de> (raw)
In-Reply-To: <20040301163532.GA7661@cs.unibo.it>

Claudio Sacerdoti Coen wrote:
>  If you really need to exclude the `Fnord value at compile time, an
>  alternative solution is to use phantom types:
> 
> type 'a foo = [ `Foo | `Bar | `Fnord ]
> let f_r (v : 'a foo) (init : ([> `NoFnord] foo) list) =
>  match v with
>    `Fnord -> init
>  | _ -> v :: init
>  ;;

But this gives me the worst of both worlds, no? I have to define a function f_r 
for every type I might want to use in place of foo, *and* the type checker can 
still see the `Fnord that isn't there:

# let l' = List.fold_right f_r [`Fnord; `Foo; `Bar] [] ;;
val l' : _[> `NoFnord] foo list = [`Foo; `Bar]
# match List.hd l' with
   | `Foo -> print_endline "Foo!"
   | `Bar -> print_endline "Bar!";;
This pattern matches values of type [< `Bar | `Foo]
but is here used to match values of type
   [> `NoFnord] foo = [ `Bar | `Fnord | `Foo]
The first variant type does not allow tag(s) `Fnord

So the "| #foo_flat as v -> v :: init" version seems to be the only workable 
solution.

Yours, Florian.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2004-03-03 10:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-01 15:09 Florian Hars
2004-03-01 16:35 ` Claudio Sacerdoti Coen
2004-03-03 10:27   ` Florian Hars [this message]
2004-03-03 10:40     ` Claudio Sacerdoti Coen

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=4045B30F.9000603@bik-gmbh.de \
    --to=hars@bik-gmbh.de \
    --cc=caml-list@inria.fr \
    --cc=sacerdot@cs.unibo.it \
    /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).