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 p8TFQ1xG006954 for ; Thu, 29 Sep 2011 17:26:01 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkQCADWNhE7RVdQ2kGdsb2JhbABBmSCOZwgUAQEBAQkJDQcUBCGBUwEBAQECARICE0cLBQsLJSE0AQUBChIGJRCHWAabTgqceoMXgxthBJh5h209hAk X-IronPort-AV: E=Sophos;i="4.68,461,1312149600"; d="scan'208";a="122168170" Received: from mail-vw0-f54.google.com ([209.85.212.54]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 29 Sep 2011 17:25:55 +0200 Received: by vws11 with SMTP id 11so1023508vws.27 for ; Thu, 29 Sep 2011 08:25:54 -0700 (PDT) Received: by 10.52.71.141 with SMTP id v13mr10365039vdu.338.1317309954481; Thu, 29 Sep 2011 08:25:54 -0700 (PDT) Received: from [192.168.1.2] (cpe-66-108-127-87.nyc.res.rr.com. [66.108.127.87]) by mx.google.com with ESMTPS id ie2sm1860137vdb.1.2011.09.29.08.25.53 (version=SSLv3 cipher=OTHER); Thu, 29 Sep 2011 08:25:54 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1244.3) Content-Type: text/plain; charset=iso-8859-1 From: Pierre Chopin In-Reply-To: Date: Thu, 29 Sep 2011 11:20:52 -0400 Cc: OCaML Mailing List Message-Id: References: To: Walter Cazzola X-Mailer: Apple Mail (2.1244.3) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p8TFQ1xG006954 Subject: Re: [Caml-list] still puzzled on generic types You need to explicitly name the optional arguments you are passing, otherwise the interpreter thinks you are trying to pass l, which should be 'a list : let rec enumerate ?(l'=[]) ?(n=0) l = match l with h::l1 -> enumerate ~l':(l'@[(n,h)]) ~n:(n+1) l1 | [] -> l' -Pierre Le 29 sept. 2011 à 11:07, Walter Cazzola a écrit : > Dear all, > waiting for some hints on my other issue for functors and generic I was > playing with an enumerate function (with tail recursion): > > let rec enumerate ?(l':((int * 'a) list)=[]) ?(n=0) l = > match l with > h::l1 -> enumerate (l'@[(n,h)]) (n+1) l1 > | [] -> l' > > this should just take a list and return a list of couple whose first > entry is the position in the list of the element; to be clearer: > > enumerate ['a'; 'b'; 'c'] -> [(0,'a'); (1,'b'); (2,'c')]; > > but this doesn't work as by type mismatch: > > Error: This expression has type (int * 'a) list > but an expression was expected of type 'a list > > Doesn't a matter if I've annotated the type (int * 'a) list > to the optional argument l' when I try to call the function with the new > value it says that the two things don't have the same type. > > I'm quite puzzled by this behavior, any explanation/help is welcome as > usual. > > Walter > -- > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs >