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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id EE91E7FACD for ; Sun, 28 Sep 2014 22:26:39 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of yminsky@janestreet.com) identity=pra; client-ip=38.105.200.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yminsky@janestreet.com"; x-sender="yminsky@janestreet.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of yminsky@janestreet.com designates 38.105.200.115 as permitted sender) identity=mailfrom; client-ip=38.105.200.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yminsky@janestreet.com"; x-sender="yminsky@janestreet.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mxout2.mail.janestreet.com) identity=helo; client-ip=38.105.200.115; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="yminsky@janestreet.com"; x-sender="postmaster@mxout2.mail.janestreet.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtcBAJluKFQmachznGdsb2JhbABgg2Fbgn22DJEFh1MCcwgWAREBAQEBAQgUCUCEBAEBBBIRBBkBASwLAQ8LCwMKAgIJHQICIQESAQUBChIGExIQiAgDEQMKnSduijh4hQIBBYh6AwqHIAERBgqBIoxCgjAHgniBU4UZAgORBoI+gjuCEIFihXCHQ4RWGCmFMFABAYJIAQEB X-IPAS-Result: AtcBAJluKFQmachznGdsb2JhbABgg2Fbgn22DJEFh1MCcwgWAREBAQEBAQgUCUCEBAEBBBIRBBkBASwLAQ8LCwMKAgIJHQICIQESAQUBChIGExIQiAgDEQMKnSduijh4hQIBBYh6AwqHIAERBgqBIoxCgjAHgniBU4UZAgORBoI+gjuCEIFihXCHQ4RWGCmFMFABAYJIAQEB X-IronPort-AV: E=Sophos;i="5.04,615,1406584800"; d="scan'208";a="98301603" Received: from mxout2.mail.janestreet.com ([38.105.200.115]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 28 Sep 2014 22:26:38 +0200 Received: from tot-smtp.delacy.com ([172.27.22.15] helo=tot-smtp) by mxout2.mail.janestreet.com with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.82) (envelope-from ) id 1XYL3F-0007kE-Bl for caml-list@inria.fr; Sun, 28 Sep 2014 16:26:37 -0400 Received: from [172.27.229.230] (helo=mxgoog1.mail.janestreet.com) by tot-smtp with esmtps (UNKNOWN:AES256-GCM-SHA384:256) (Exim 4.72) (envelope-from ) id 1XYL3F-0002dQ-94 for caml-list@inria.fr; Sun, 28 Sep 2014 16:26:37 -0400 Received: from mail-ig0-f176.google.com ([209.85.213.176]) by mxgoog1.mail.janestreet.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.72) (envelope-from ) id 1XYL3F-0001OH-63 for caml-list@inria.fr; Sun, 28 Sep 2014 16:26:37 -0400 Received: by mail-ig0-f176.google.com with SMTP id hn18so1993566igb.15 for ; Sun, 28 Sep 2014 13:26:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=rco6E+NjjDXxm3PvF4w+qw03EcS657kDIAHt8T2boxg=; b=AqvdpffiXKQLbpdpT47oXdHn5lEq16L35Jj3sh0skiSngifnwXTVf/1HhSC3eW6s2e Xfeyvnaz6+8ocPVqxc1OdkJ6P2DHA8hYvPmrnr9PpPWjNDEJtDmVjFn4V/XMsm1PSX5W gR23pRuPFP5NMmZu+HHJ+ZhdpqWfUcf6ybx0Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=rco6E+NjjDXxm3PvF4w+qw03EcS657kDIAHt8T2boxg=; b=AE9mP9HJlL507WPTmIQwPrUSYUMVEFbBYTjoNpVq91Ud3gGTir7X/Ymu0JBjVxmRq1 Wi4JLB7711zSLohYdaxnh3YWDhrxqZTDvsFE/ZGLd0HGl1YnEe/hNdQshlobEtKvcH0p rpcswPOk/8mVKBDvtuXAVUz948vyY55aKTwtApQTXSFP171XfIcWUNDLo5BPENmQMQzm 5aY+weGylTcKgUF7e32DYC7+vpfRzZG9juvsUAvzIXoJyiLgHbuq+tI/c8evrVpJtpp6 MGk2jQ9bBWrUjqbn+boECKqaO+DScj2dgwjXvJAUZyMHggEQnE+MY5j1IPa4JoOuvK7l r84w== X-Gm-Message-State: ALoCoQmsvKAhS1suOtKPKweO0B5Os2sgjvlzZNmaFZmNnH2JDtijKE92T+S5T+8Xom4FCJ5FcDlXzzSRwl+TSfIXFep+46YET9lR6e91JVGEmE5udMyod0po/w4B6PdvjwYro0HaeNhv X-Received: by 10.50.30.165 with SMTP id t5mr27936976igh.48.1411935996787; Sun, 28 Sep 2014 13:26:36 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.50.30.165 with SMTP id t5mr27936965igh.48.1411935996629; Sun, 28 Sep 2014 13:26:36 -0700 (PDT) Received: by 10.107.129.88 with HTTP; Sun, 28 Sep 2014 13:26:36 -0700 (PDT) In-Reply-To: <87bnpzpm0l.fsf@gmail.com> References: <87bnpzpm0l.fsf@gmail.com> Date: Sun, 28 Sep 2014 16:26:36 -0400 Message-ID: From: Yaron Minsky To: Malcolm Matalka Cc: Shuai Wang , "caml-list@inria.fr" Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] Why List.map does not be implemented tail-recursively? Indeed, the implementation from that post did make it into Core_kernel. Here's the link: https://github.com/janestreet/core_kernel/blob/release-112.01.00/lib/core_list.ml#L380 y On Sun, Sep 28, 2014 at 3:45 PM, Malcolm Matalka wrote: > https://blogs.janestreet.com/optimizing-list-map/ > > And from the horse's mouth: > > https://groups.google.com/forum/#!msg/fa.caml/YaLYqkpn928/1jdo8a0K6AEJ > > Shuai Wang writes: > >> 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 > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs