Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Beginner's question.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Alexander A. Vlasov <zulu@g...>
Subject: Beginner's question.

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 ( lst))

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

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