[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jean-Christophe Filliatre <filliatr@l...> |
| Subject: | Re: [Caml-list] Beginner's question. |
Alexander A. Vlasov writes: > 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. > > 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) "function" defines a function over an anonymous argument which is immediatly filtered by the patterns. So your function mapm has actually 3 arguments, the 3rd of which is a pattern. I guess you intended to do some pattern matching on the two arguments of your function, which would be let rec mapm func list = match func, list with | _, [] -> [] | _, head :: tail -> func head :: mapm func tail but there is no need to do some pattern matching on the function, so let rec mapm func = function | [] -> [] | head : :tail -> func head :: mapm func tail would equally do, which is (regardless of the evaluation order) the code of List.map that you can find in the ocaml standard library. I you don't mind a comment: I think there is also a mailing list for ocaml beginners. Best regards, -- Jean-Christophe Filliātre (http://www.lri.fr/~filliatr)