caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] still puzzled on generic types
@ 2011-09-29 15:07 Walter Cazzola
  2011-09-29 15:16 ` David Allsopp
  2011-09-29 15:20 ` Pierre Chopin
  0 siblings, 2 replies; 6+ messages in thread
From: Walter Cazzola @ 2011-09-29 15:07 UTC (permalink / raw)
  To: OCaML Mailing List

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
-- 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-09-29 19:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-29 15:07 [Caml-list] still puzzled on generic types 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
2011-09-29 15:32   ` Walter Cazzola

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).