From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 682E18239C for ; Fri, 22 Dec 2017 12:05:34 +0100 (CET) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=mail@matej-kosik.net; spf=SoftFail smtp.mailfrom=mail@matej-kosik.net; spf=SoftFail smtp.helo=postmaster@matej-kosik.net Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of mail@matej-kosik.net) identity=pra; client-ip=145.239.83.105; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="mail@matej-kosik.net"; x-sender="mail@matej-kosik.net"; x-conformance=sidf_compatible Received-SPF: SoftFail (mail3-smtp-sop.national.inria.fr: domain of mail@matej-kosik.net is inclined to not designate 145.239.83.105 as permitted sender) identity=mailfrom; client-ip=145.239.83.105; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="mail@matej-kosik.net"; x-sender="mail@matej-kosik.net"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: SoftFail (mail3-smtp-sop.national.inria.fr: domain of postmaster@matej-kosik.net is inclined to not designate 145.239.83.105 as permitted sender) identity=helo; client-ip=145.239.83.105; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="mail@matej-kosik.net"; x-sender="postmaster@matej-kosik.net"; x-conformance=sidf_compatible; x-record-type="v=spf1" IronPort-PHdr: =?us-ascii?q?9a23=3AbuAXCRadc24+GHzLAcmvXz//LSx+4OfEezUN459i?= =?us-ascii?q?sYplN5qZr8y/bnLW6fgltlLVR4KTs6sC17KP9fi4EUU7or+5+EgYd5JNUxJXwe?= =?us-ascii?q?43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRp?= =?us-ascii?q?OOv1BpTSj8Oq3Oyu5pHfeQpFiCagbb9oMBm6sRjau9ULj4dlNqs/0AbCrGFS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oQLm6BJvOE9j+yIeK2z22S9gPPjhL?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0BsGQCc5Txa/2lT75FdHQEBBQELAYM+R?= =?us-ascii?q?iADcSeEBosYj3iZZAcoiWVFEwEBAQEBAQEBAQFqKII4JAGCcASBLwJfDQgBAYo?= =?us-ascii?q?uDKV3gW06iFOCJwoFhAuCZoMUDIYoAYUFgmUFik6Ye4RRgi2BA5lGh2KNIYsZN?= =?us-ascii?q?yElgSp6CoJmhFd3BYl7AQEB?= X-IPAS-Result: =?us-ascii?q?A0BsGQCc5Txa/2lT75FdHQEBBQELAYM+RiADcSeEBosYj3i?= =?us-ascii?q?ZZAcoiWVFEwEBAQEBAQEBAQFqKII4JAGCcASBLwJfDQgBAYouDKV3gW06iFOCJ?= =?us-ascii?q?woFhAuCZoMUDIYoAYUFgmUFik6Ye4RRgi2BA5lGh2KNIYsZNyElgSp6CoJmhFd?= =?us-ascii?q?3BYl7AQEB?= X-IronPort-AV: E=Sophos;i="5.45,440,1508796000"; d="asc'?scan'208";a="249267194" Received: from 105.ip-145-239-83.eu (HELO matej-kosik.net) ([145.239.83.105]) by mail3-smtp-sop.national.inria.fr with ESMTP; 22 Dec 2017 12:05:33 +0100 Received: from [192.168.1.11] (adsl-dyn-242.95-102-7.t-com.sk [95.102.7.242]) by matej-kosik.net (Postfix) with ESMTPSA id 8BF5623827 for ; Fri, 22 Dec 2017 12:05:32 +0100 (CET) To: OCaml Mailing List From: =?UTF-8?B?TWF0ZWogS2/FocOtaw==?= Openpgp: id=1CD41D0A52319DC7ABC1B79F50AFFA128CE48649; url=http://matej-kosik.net/doc/kosik.asc Message-ID: <64f1e880-fb8c-4432-3597-3485ec06c046@matej-kosik.net> Date: Fri, 22 Dec 2017 12:05:31 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="lqT34glAII3T0xPOEZfQzsYDQ5EUGMCF2" Subject: [Caml-list] =?UTF-8?Q?stdlib_=E2=86=92_Queue_=E2=86=92_iter_=3A_i?= =?UTF-8?Q?mplementation_question_/_=28possibly=29_bikeshedding?= This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --lqT34glAII3T0xPOEZfQzsYDQ5EUGMCF2 Content-Type: multipart/mixed; boundary="33vCZkfTHq7fs1oB3azjh68s2iPplxahu"; protected-headers="v1" From: =?UTF-8?B?TWF0ZWogS2/FocOtaw==?= To: OCaml Mailing List Message-ID: <64f1e880-fb8c-4432-3597-3485ec06c046@matej-kosik.net> Subject: =?UTF-8?Q?stdlib_=e2=86=92_Queue_=e2=86=92_iter_:_implementation_qu?= =?UTF-8?Q?estion_/_=28possibly=29_bikeshedding?= --33vCZkfTHq7fs1oB3azjh68s2iPplxahu Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable Hi, I just had a look at Queue.iter function as it is implemented by Ocaml stan= dard library. The original version (* https://github.com/ocaml/ocaml/blob/c08532f561548f6164278ba0d156da841a= efe44a/stdlib/queue.ml#L100-L108 *) let iter =3D let rec iter f cell =3D match cell with | Nil -> () | Cons { content; next } -> f content; iter f next in fun f q -> iter f q.first I am wondering about two things. ---------------------------------------------------------------------------= ----- (1) Why is the original implementation preferred over let iter f =3D let rec iter cell =3D match cell with | Nil -> () | Cons { content; next } -> f content; iter next in fun q -> iter q.first where "f" would be bound once and then reused as many times as necessary (instead of passed over and over again within the inner "iter" loop). ---------------------------------------------------------------------------= ----- (2) Why is the original implementation preferred over the following version let iter f q =3D let rec iter cell =3D match cell with | Nil -> () | Cons { content; next } -> f content; iter next in iter q.first ? Similar decisions where made elsewhere in stdlib so I am wondering what am = I missing? --33vCZkfTHq7fs1oB3azjh68s2iPplxahu-- --lqT34glAII3T0xPOEZfQzsYDQ5EUGMCF2 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEHNQdClIxncerwbefUK/6EozkhkkFAlo85vsACgkQUK/6Eozk hkkrPQ/8D3Enn7Q0UhVS3h8VDUixVh+0Vsb08axS8lCWmLZK7xEmIFZ6m300xULC y2hWP7npMD5lTQHNMD0MDqzJbZOCC5YYxI1jdxa+YoJ6PfhSX3iVtepdYl6y1+vg C+wzZ/8HB83Mfj8mcV4vlgCBKoJ48PHw793TPToUnIew0hxLCNpXJBDFO8Z7RkNr hDuPz/GVeEqHkW0v2n7Ao59yFt0DgkNWTeekphOHblefn5Ag9LHMPYsPVU9z9TrX kWF3lNvCVSsW/WoEFrf08GXD9jcLVGAtwhx9yShdeVbrjXvxii5+HA4LOrlYVN/0 92sPVYoBKrxXaEdVZKjNGxIGS9HRMx4vIvfVsyAgItK7fj++ZlmVVI7O2xkOfCOe myFfqIPHdXk9usr/LmdpFL9k/UeyTeZMWmijDPl7b0Jz2q43EdHGzJb8s3NQSDYb doPGi+DUAbSaXDD0EnYFctKT1qCsggVZ3zmThbGY+rJi1typtogRka6saFbhzle+ Fc1cibi+yzQoFaQCw8vDroaHvAl5DZ1AMoXe2X9zHyiVAlgID5sYojrdVBfE8dk6 qbaPR5crkSf0RzubX+KDWg6nu4qa0fYCzl5U7MHFP3qs9unAS2f2LnZDnpRfAJKC hngmZ1L7VR14w9rT7fAVhBd3xOEods4LAQwYlUx9lEM7+Lhk7kk= =cdub -----END PGP SIGNATURE----- --lqT34glAII3T0xPOEZfQzsYDQ5EUGMCF2--