From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id JAA08848 for caml-red; Tue, 6 Jun 2000 09:33:45 +0200 (MET DST) 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 DAA17173 for ; Tue, 6 Jun 2000 03:10:47 +0200 (MET DST) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by nez-perce.inria.fr (8.10.0/8.10.0) with ESMTP id e561AkT14731; Tue, 6 Jun 2000 03:10:47 +0200 (MET DST) Received: from localhost (patrick@localhost) by fledge.watson.org (8.9.3/8.9.3) with SMTP id VAA16056; Mon, 5 Jun 2000 21:10:45 -0400 (EDT) (envelope-from patrick@watson.org) Date: Mon, 5 Jun 2000 21:10:45 -0400 (EDT) From: Patrick M Doane To: Pierre Weis cc: Markus Mottl , caml-list@inria.fr Subject: Re: Typing of patterns In-Reply-To: <200006051356.PAA17512@pauillac.inria.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: weis On Mon, 5 Jun 2000, Pierre Weis wrote: > However, we get a strange difference in typing since, as you > mentioned, the explicit ``as clause'' does not set up a typing > connection between input and output : > > let (ensure_nil : 'a pliste -> 'b pliste) = function > | `Cons (x, l) -> failwith "Not nil" > | `Nil as l -> l;; > val ensure_nil : 'a pliste -> 'b pliste = > > Jacques may explain us if the above suggested generalization scheme is > used for identifiers bound in as clauses of patterns (and if not, > which scheme is used ?)... This discussion seems related to a recent typing difficulty I have had with polymorphic variants. I want to change the data associated to a particular constructor of a variant and leave the others unmodified: # let f = function `A -> `A () | _ as t -> t;; Characters 41-42: This expression has type [< `A | ..] but is here used with type [> `A of unit] Notice that the type for '_' includes `A when it obviously cannot. One could include every possible expected type in place of '_' but that removes one of the advantages of polymorphic variants: that the type can be refined and extended easily. While further exploring this issue I managed to get an uncaught exception from the type checker: # let f = function `A true -> () | `A 5 -> ();; Uncaught exception: File "typing/parmmatch.ml", ... Taking the conjuction of 'unit' and 'int' does seem to work however, # let f = function `A -> () | `A 5 -> ();; val f : [< `A of & int] -> unit = but it prints the type without mentioning 'unit'. Patrick Doane