caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Beginner's question.
@ 2005-10-27 13:30 Alexander A. Vlasov
  2005-10-27 13:41 ` [Caml-list] " Luc Maranget
  2005-10-27 13:50 ` Jean-Christophe Filliatre
  0 siblings, 2 replies; 4+ messages in thread
From: Alexander A. Vlasov @ 2005-10-27 13:30 UTC (permalink / raw)
  To: caml-list

Hello.

I'm making my first steps in OCaml and trying (just for expirience) to
implement a simple function which applies given function to all elements
of given list.
I successfully did it using if/then/else

let rec map func lst =
        if lst = [] then []
        else (func (List.hd lst)) :: (map func (List.tl lst))
;;

But I can't do it using pattern matching -- following function doesn't
work

let rec mapm func lst = function
        | ( _, [] ) -> []
        | ( _, head::tail ) -> (func head) :: (mapm func tail)
;;

I get type mismatch error: characters 39-55:
This expression has type 'a * 'b list -> 'c list but is here used with
type  'c list

But wait, ``map func (List.tl lst)''  in first example has the same
type, isn't it?
Both right parts in first and second example are, say, transformers from
a tuple ( something, list-of-something-else ) to list-of-something-else.

I understand that I missed something, so please tell me what.
and... thank you for your patience 8)



-- 
Best regards,
Alexander A. Vlasov.


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

end of thread, other threads:[~2005-10-27 14:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-27 13:30 Beginner's question Alexander A. Vlasov
2005-10-27 13:41 ` [Caml-list] " Luc Maranget
2005-10-27 14:40   ` Damien Doligez
2005-10-27 13:50 ` Jean-Christophe Filliatre

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