From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p76H3pRP027465 for ; Sat, 6 Aug 2011 19:03:51 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnMBALlyPU5V2gB5nGdsb2JhbABCp34BAQEBAQgLCQkUJYFAAQEFJ1IQC0YUKCGIAr0cDoVZXwSjbA X-IronPort-AV: E=Sophos;i="4.67,329,1309730400"; d="scan'208";a="104848540" Received: from emailfrontal2.citycable.ch ([85.218.0.121]) by mail4-smtp-sop.national.inria.fr with SMTP; 06 Aug 2011 19:03:46 +0200 X-Alinto-smtpauth-localdomain: Yes Received: from seldon (unknown [85.218.93.111]) (Authenticated sender: guillaume.yziquel@citycable.ch) by emailfrontal2.citycable.ch (Postfix) with ESMTPA id 5AE6DF08009; Sat, 6 Aug 2011 19:03:38 +0200 (CEST) Received: from yziquel by seldon with local (Exim 4.72) (envelope-from ) id 1QpkH9-0003nx-K4; Sat, 06 Aug 2011 19:03:03 +0200 Date: Sat, 6 Aug 2011 19:03:03 +0200 From: Guillaume Yziquel To: Fabrice Le Fessant Cc: caml-list@inria.fr, rixed@happyleptic.org Message-ID: <20110806170303.GE17793@localhost> References: <20110806125021.GB10154@ombreroze.happyleptic.org> <4E3D3A89.90007@inria.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <4E3D3A89.90007@inria.fr> User-Agent: Mutt/1.5.20 (2009-06-14) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p76H3pRP027465 Subject: Re: [Caml-list] typer strangeness (3.12.0) Le Saturday 06 Aug 2011 à 14:58:49 (+0200), Fabrice Le Fessant a écrit : > The type constraint that you specified does not constraint the > polymorphism of the type. To declare a polymorphic constraint, you must > use (with OCaml >= 3.12.0) : > > let pipe : 'a 'b 'c. ('a, 'b) parzer -> ('c, 'a) parzer -> ('c, 'b) parzer = > fun 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) > | x -> x) > > In which case you get the following error : > Error: This definition has type > 'a 'b. ('b, 'b) parzer -> ('a, 'b) parzer -> ('a, 'b) parzer > which is less general than > 'c 'd 'e. ('e, 'd) parzer -> ('c, 'e) parzer -> ('c, 'd) parzer > > Fabrice You can achieve a similar goal with stuff like: # let f (type a) (type b) (x : a) = (x : b);; Error: This expression has type a but an expression was expected of type b The benefit of which is that you do not have f explicitely quantified as opposed to the "let f : 'a 'b. ..." alternative. Feels more ocaml-ish to me. -- Guillaume Yziquel