From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p76CoZ50021950 for ; Sat, 6 Aug 2011 14:50:35 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkoCAGQ3PU7UGyoEkWdsb2JhbABCmGOPBxQBAQEBCQsLBxQDIoFuE4EOJiiII588n0OFZ18Eo2w X-IronPort-AV: E=Sophos;i="4.67,328,1309730400"; d="scan'208";a="115136217" Received: from smtp4-g21.free.fr ([212.27.42.4]) by mail1-smtp-roc.national.inria.fr with ESMTP; 06 Aug 2011 14:50:29 +0200 Received: from ombreroze.happyleptic.org (unknown [82.229.213.209]) by smtp4-g21.free.fr (Postfix) with ESMTP id 229354C809B for ; Sat, 6 Aug 2011 14:50:22 +0200 (CEST) Received: from rixed by ombreroze.happyleptic.org with local (Exim 4.76) (envelope-from ) id 1QpgKb-0002nO-EP for caml-list@inria.fr; Sat, 06 Aug 2011 14:50:21 +0200 Date: Sat, 6 Aug 2011 14:50:21 +0200 From: rixed@happyleptic.org To: caml-list@inria.fr Message-ID: <20110806125021.GB10154@ombreroze.happyleptic.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Subject: [Caml-list] typer strangeness (3.12.0) Given these types: (* A parser is given a list of items and returns either a Failure indication, a Wait for more inputs indication, or a result (composed of a new value and the list of tokens that were unused) *) type ('a, 'b) parzer_result = Wait | Res of ('a * 'b list) | Fail type ('a, 'b) parzer = 'b list -> ('a, 'b) parzer_result And this function used to pipe two parsers together: (* Use the results of the first parser as the input elements of the second. Stop as soon as p2 returns a result or fails. Notice that if p1 is a ('a, 'b) parzer and p2 a ('c, 'a) parzer then pipe p1 p2 is a ('c, 'b) parzer, which comes handy but p2 is then forced to consume everything ! *) let (pipe : ('a, 'b) parzer -> ('c, 'a) parzer -> ('c, 'b) parzer) p1 p2 = let p1_rem = ref [] in fun bs -> match p1 (!p1_rem @ bs) with | Fail -> Fail | Wait -> Wait | Res (res, rem) -> p1_rem := rem ; (match p2 [res] with | Res (res', rem') -> if rem' <> [] then Printf.printf "WRN: second end of a pipe did not consume eveything !\n" ; Res (res', !p1_rem) | Fail -> Fail | Wait -> Wait) This pipe function has the expected type : # pipe;; - : ('a, 'b) parzer -> ('c, 'a) parzer -> ('c, 'b) parzer = Now, if I change it's last line for : "| x -> x)", ie not repeating Wait and Fail, the result is very different : # pipe;; - : ('a, 'a) parzer -> ('b, 'a) parzer -> ('b, 'a) parzer = How come? And why didn't the compiler complain since I explicitely typed the function definition?