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 9380E7FACD for ; Sun, 28 Sep 2014 21:31:55 +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.176; 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.176 as permitted sender) identity=mailfrom; client-ip=209.85.217.176; 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-f176.google.com) identity=helo; client-ip=209.85.217.176; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="wangshuai901@gmail.com"; x-sender="postmaster@mail-lb0-f176.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtUBAPRhKFTRVdmwm2dsb2JhbABggkiBGVuCfccPh1N1CBYBEQEBAQEBBgsLCRQshBwRBBkBGx4DEhA3AiQBEQEFAVeIBwEDEQ2aFoMdboswgXKDEIg1ChknDWeGSwEBBA6QDCGCYoFTBYZbj0SCPoRLk2sYKYUwIS8BgkkBAQE X-IPAS-Result: AtUBAPRhKFTRVdmwm2dsb2JhbABggkiBGVuCfccPh1N1CBYBEQEBAQEBBgsLCRQshBwRBBkBGx4DEhA3AiQBEQEFAVeIBwEDEQ2aFoMdboswgXKDEIg1ChknDWeGSwEBBA6QDCGCYoFTBYZbj0SCPoRLk2sYKYUwIS8BgkkBAQE X-IronPort-AV: E=Sophos;i="5.04,615,1406584800"; d="scan'208";a="81188735" Received: from mail-lb0-f176.google.com ([209.85.217.176]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 28 Sep 2014 21:31:29 +0200 Received: by mail-lb0-f176.google.com with SMTP id p9so1203408lbv.7 for ; Sun, 28 Sep 2014 12:31:29 -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=m1fmS3NHyYGbnnas9yJ0UYSjGtb3p1TRcarpuh/480c=; b=LBRLIekJOYh/9IWLD3zvriFUASa57vOznDMeH0pEtrzKXqs7dXdEQ3f3vYM0v1iy64 6sp80N0G2N2+fINNlfGgb2rua6uKCLbsUn7ijPIK2WK34K+frFKykieW6m2R8T9DB3gj T+Rno5zT/pyY6BytZygeHYac/8ljpt0ZmFvROl86KyxY+ijuh2cJDVOAOobL2TjjBQ+N tzER95rDV4R4JXs+3Ct/dRtQ8G3WHvs8m7S+GfXv3zx2M80wS99TRboJrv4eDjTjf44U sSFYNdzjlTxkEDjAf2ggl6xImxVHXfYQr5+28Fb5cXeSH2Zoo9n4ZpbSt4XNXBU7bRI/ A6Zw== MIME-Version: 1.0 X-Received: by 10.152.36.37 with SMTP id n5mr4191495laj.93.1411932688930; Sun, 28 Sep 2014 12:31:28 -0700 (PDT) Received: by 10.114.59.101 with HTTP; Sun, 28 Sep 2014 12:31:28 -0700 (PDT) Date: Sun, 28 Sep 2014 15:31:28 -0400 Message-ID: From: Shuai Wang To: caml-list@inria.fr Content-Type: multipart/alternative; boundary=089e0160a97e5edd3a050425325d Subject: [Caml-list] Why List.map does not be implemented tail-recursively? --089e0160a97e5edd3a050425325d 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 --089e0160a97e5edd3a050425325d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello list,

I am wor= king on some stack_overflow exception in our recent project written in OCam= l
and event= ually it turns out that this exception is thrown by List.map function.

By seeing the source = code of OCaml's=C2=A0List module= , it seems that map function=C2=A0
does not be implemented tail-recursively:=C2=A0

let rec map f =3D function
    [] -> []
  | a::l -> let r =3D f a in r :: map f l




--089e0160a97e5edd3a050425325d--