From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA08919; Wed, 3 Mar 2004 11:28:01 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA08941 for ; Wed, 3 Mar 2004 11:28:00 +0100 (MET) Received: from grisu.bik-gmbh.de (grisu.bik-gmbh.de [217.110.154.194]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i23AS9Iq024266 for ; Wed, 3 Mar 2004 11:28:09 +0100 Received: from bik-gmbh.de ([192.168.125.193]) by grisu.bik-gmbh.de (8.12.8p2/8.12.8) with ESMTP id i23ARW6K017294; Wed, 3 Mar 2004 11:27:32 +0100 (CET) (envelope-from hars@bik-gmbh.de) Message-ID: <4045B30F.9000603@bik-gmbh.de> Date: Wed, 03 Mar 2004 11:27:27 +0100 From: Florian Hars User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7a) Gecko/20040209 X-Accept-Language: de, de-de, en-us, en MIME-Version: 1.0 To: Claudio Sacerdoti Coen CC: caml-list@inria.fr Subject: Re: [Caml-list] Getting rid of impossible polymorphic variant tags from infered types References: <4043520E.2040802@bik-gmbh.de> <20040301163532.GA7661@cs.unibo.it> In-Reply-To: <20040301163532.GA7661@cs.unibo.it> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-2.6 required=5.0 tests=EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT,REFERENCES, REPLY_WITH_QUOTES,USER_AGENT_MOZILLA_UA,X_ACCEPT_LANG version=2.55 X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp) X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; florian:01 hars:01 hars:01 bik-gmbh:01 caml-list:01 sacerdoti:01 coen:01 foo:01 foo:01 checker:01 val:01 endline:01 endline:01 florian:01 phantom:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 33 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