caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pierre Chopin <pierre@punchup.com>
To: Walter Cazzola <cazzola@dico.unimi.it>
Cc: OCaML Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] still puzzled on generic types
Date: Thu, 29 Sep 2011 11:20:52 -0400	[thread overview]
Message-ID: <ECCFE43B-CB21-4541-917D-D42FF98F098B@punchup.com> (raw)
In-Reply-To: <alpine.LFD.2.00.1109291700550.4431@surtur.dico.unimi.it>

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
> 



  parent reply	other threads:[~2011-09-29 15:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-29 15:07 Walter Cazzola
2011-09-29 15:16 ` David Allsopp
2011-09-29 15:29   ` Walter Cazzola
2011-09-29 19:04     ` David Allsopp
2011-09-29 15:20 ` Pierre Chopin [this message]
2011-09-29 15:32   ` Walter Cazzola

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ECCFE43B-CB21-4541-917D-D42FF98F098B@punchup.com \
    --to=pierre@punchup.com \
    --cc=caml-list@inria.fr \
    --cc=cazzola@dico.unimi.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).