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 QAA16202; Mon, 1 Mar 2004 16:09:14 +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 QAA16191 for ; Mon, 1 Mar 2004 16:09:13 +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 i21F9KIq029935 for ; Mon, 1 Mar 2004 16:09:20 +0100 Received: from bik-gmbh.de ([192.168.125.193]) by grisu.bik-gmbh.de (8.12.8p2/8.12.8) with ESMTP id i21F976K086041 for ; Mon, 1 Mar 2004 16:09:07 +0100 (CET) (envelope-from hars@bik-gmbh.de) Message-ID: <4043520E.2040802@bik-gmbh.de> Date: Mon, 01 Mar 2004 16:09:02 +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: caml-list@inria.fr Subject: [Caml-list] Getting rid of impossible polymorphic variant tags from infered types Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-0.1 required=5.0 tests=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 infers:01 val:01 nonetheless:01 inventing:01 checker:01 foo:01 foo:01 florian:01 compiler:01 ocaml:01 polymorphic:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 5 If I write a function to filter out all occurences of values of a specific polymorphic variant tag from a list, ocaml infers a return type for this function of any type that may contain the tag I have just removed: # let f l = List.filter (function `Fnord -> false | _ -> true) l;; val f : ([> `Fnord] as 'a) list -> 'a list = While I unterstand why this type is infered, it is nonetheless wrong, it should be something like [> 'a \ `Fnord ] list (inventing notation on the fly). Is there some decent way to tell the compiler that I know more about this function than the type checker does? The following should be safe, but doesn't strike me as especially elegant and makes the type more restrictive than I'd like it to be: type foo = [ `Foo | `Bar | `Fnord ] type foo_flat = [ `Foo | `Bar ] let f' l = let f_r (v: foo) (init: foo_flat list) = match v with | `Fnord -> init | _ -> Obj.magic v :: init in List.fold_right f_r l [] 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