caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe Filliatre <filliatr@lri.fr>
To: "Alexander A. Vlasov" <zulu@galaradio.com>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Beginner's question.
Date: Thu, 27 Oct 2005 15:50:05 +0200	[thread overview]
Message-ID: <17248.56077.589928.491952@gargle.gargle.HOWL> (raw)
In-Reply-To: <1130419808.12902.13.camel@localhost.localdomain>


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)


      parent reply	other threads:[~2005-10-27 13:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-27 13:30 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 message]

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=17248.56077.589928.491952@gargle.gargle.HOWL \
    --to=filliatr@lri.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=zulu@galaradio.com \
    /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).