From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 499B37FACD for ; Sun, 28 Sep 2014 21:28:25 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of wangshuai901@gmail.com) identity=pra; client-ip=209.85.217.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="wangshuai901@gmail.com"; x-sender="wangshuai901@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of wangshuai901@gmail.com designates 209.85.217.173 as permitted sender) identity=mailfrom; client-ip=209.85.217.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="wangshuai901@gmail.com"; x-sender="wangshuai901@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-lb0-f173.google.com) identity=helo; client-ip=209.85.217.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="wangshuai901@gmail.com"; x-sender="postmaster@mail-lb0-f173.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtUBAM1gKFTRVdmtm2dsb2JhbABggkiBGVuCfccPh1N1CBYBEQEBAQEBBgsLCRQshBwRBBkBGx4DEhA3AiQBEQEFAVeIBwEDEQ2aF4MdboswgXKDEIg2ChknDWeGSwEBBA6QDCGCYoFTBYZbj0SCPoRLk2sYKYUwIS8BgkkBAQE X-IPAS-Result: AtUBAM1gKFTRVdmtm2dsb2JhbABggkiBGVuCfccPh1N1CBYBEQEBAQEBBgsLCRQshBwRBBkBGx4DEhA3AiQBEQEFAVeIBwEDEQ2aF4MdboswgXKDEIg2ChknDWeGSwEBBA6QDCGCYoFTBYZbj0SCPoRLk2sYKYUwIS8BgkkBAQE X-IronPort-AV: E=Sophos;i="5.04,615,1406584800"; d="scan'208";a="81188523" Received: from mail-lb0-f173.google.com ([209.85.217.173]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 28 Sep 2014 21:28:24 +0200 Received: by mail-lb0-f173.google.com with SMTP id 10so14907534lbg.4 for ; Sun, 28 Sep 2014 12:28:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=gH4Q2Bj/z9uGhC4vr0oD9G6ZEl5nkG/ZjCRz9seTROU=; b=ITkQnn3x4ct1pcb3AAsd6F4E67+7wKD4nc7I6ik7tOVW3zKWAGIL1dHDrkoMuTCqRx DGoLunI0t1DPQn8L/OU05YKPNX/gtAZ/0sLhIiCoyWCtv0AToEzFhnClnuz+sjX1tAbN s7EQKDeffYzme+DheObk1o/5zOeXkiHl+lwOAc5ac1vhisl3vGBDfYsz0ahtmU8bFMMi O7CzpKEifNY0NLosrNRxJt2nh7J+VxvZrVglezqR884eMo1tjzcpZsNGh8OiBf2alhDV O2ewSbb8Ucv/4CjSefE2KB4amz0aETrh/g1iFSjF+yeK5xgsYBoYuIav8mtMB9dk71uG YEVw== MIME-Version: 1.0 X-Received: by 10.112.13.10 with SMTP id d10mr32735911lbc.10.1411932503579; Sun, 28 Sep 2014 12:28:23 -0700 (PDT) Received: by 10.114.59.101 with HTTP; Sun, 28 Sep 2014 12:28:23 -0700 (PDT) Date: Sun, 28 Sep 2014 15:28:23 -0400 Message-ID: From: Shuai Wang To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=001a11c3a11a52a36a0504252712 Subject: [Caml-list] Why List.map does not be implemented tail-recursively? --001a11c3a11a52a36a0504252712 Content-Type: text/plain; charset=UTF-8 Hello list, I am working on some stack_overflow exception in our recent project written in OCaml and eventually it turns out that this exception is thrown by List.map function. By seeing the source code of OCaml's List module , it seems that map function does not be implemented tail-recursively: let rec map f = function [] -> [] | a::l -> let r = f a in r :: map f l So my question is: *Why would OCaml's implementation List.map like this? * In my humble option, it definitely should be written in a tail-recursive way, and it not, stack_overflow would be unavoidable. For example in order to handle the exception, I abandon the code using List.map and rewrite it into a tail-recursive help function. Best, Shuai --001a11c3a11a52a36a0504252712 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello list,


I am working= on some stack_overflow exception in our recent project written in OCaml
and eventually it turns out that this exception is thrown by List.m= ap function.

By seeing the source code of OCaml= 9;s List module, it seems that map f= unction=C2=A0
--001a11c3a11a52a36a0504252712--