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 DAB137F613 for ; Tue, 13 Sep 2016 17:38:58 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=dra-news@metastack.com; spf=Pass smtp.mailfrom=dra-news@metastack.com; spf=None smtp.helo=postmaster@outmail148113.authsmtp.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of dra-news@metastack.com) identity=pra; client-ip=62.13.148.113; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dra-news@metastack.com"; x-sender="dra-news@metastack.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of dra-news@metastack.com designates 62.13.148.113 as permitted sender) identity=mailfrom; client-ip=62.13.148.113; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dra-news@metastack.com"; x-sender="dra-news@metastack.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@outmail148113.authsmtp.com) identity=helo; client-ip=62.13.148.113; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="dra-news@metastack.com"; x-sender="postmaster@outmail148113.authsmtp.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3A4mkfFRVb+JJgsVogmqxpmHUK0obV8LGtZVwlr6E/?= =?us-ascii?q?grcLSJyIuqrYZheGt8tkgFKBZ4jH8fUM07OQ6PG5HzNYqsbZ+DBaKdoXCE9D0Z?= =?us-ascii?q?1X1yUbQ+e7SmTDZMbwaCI7GMkQHHRExFqcdXZvJcDlelfJqWez5zNBUj/2NA5y?= =?us-ascii?q?O/inUtWK15f/hKiO/Mj6Y+xQidP1S75qxRC/rU2FqMoQgKNzI6A9xwuPuGYeP6?= =?us-ascii?q?wczmptIReXng3gzsa25p9qtSpK8bp1/MdFVeD+fr8kZb1eFjUvdW4vsp7Frx7G?= =?us-ascii?q?GCeG+HoQGkwSlgFPGxCNuB3gV9L3vzThnu9wxCCBIcT9TvY/XjH0vPQjcwPhlC?= =?us-ascii?q?pSb21xy2rQkMEl1K8=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0DrAgB9HNhXh3GUDT5dHQEFAQsBgygSA?= =?us-ascii?q?QEBAQF1fAEGoyEBAQaEIZMEJIV6AoFMOxEBAQEBAQEBAQEBARIBAQEKCwkJGS+?= =?us-ascii?q?CMhiCFwEBAQQDARxpAgEGAhguMiUCBAEaiEMDAQmTVp0ZCIw1AQEIAQEBASOBB?= =?us-ascii?q?IRkhReEQoJ+LYIvAQSZZYYliSsKgjKNJpBTNIMkgVhwAYZhfwEBAQ?= X-IPAS-Result: =?us-ascii?q?A0DrAgB9HNhXh3GUDT5dHQEFAQsBgygSAQEBAQF1fAEGoyE?= =?us-ascii?q?BAQaEIZMEJIV6AoFMOxEBAQEBAQEBAQEBARIBAQEKCwkJGS+CMhiCFwEBAQQDA?= =?us-ascii?q?RxpAgEGAhguMiUCBAEaiEMDAQmTVp0ZCIw1AQEIAQEBASOBBIRkhReEQoJ+LYI?= =?us-ascii?q?vAQSZZYYliSsKgjKNJpBTNIMkgVhwAYZhfwEBAQ?= X-IronPort-AV: E=Sophos;i="5.30,329,1470693600"; d="scan'208";a="236313209" Received: from outmail148113.authsmtp.com ([62.13.148.113]) by mail2-smtp-roc.national.inria.fr with ESMTP; 13 Sep 2016 17:38:57 +0200 Received: from mail-c247.authsmtp.com (mail-c247.authsmtp.com [62.13.128.247]) by punt21.authsmtp.com (8.14.2/8.14.2/) with ESMTP id u8DFcvZ5046128; Tue, 13 Sep 2016 16:38:57 +0100 (BST) Received: from romulus.metastack.com (114.212-105-213.static.virginmediabusiness.co.uk [213.105.212.114]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/) with ESMTP id u8DFcthd001414 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 13 Sep 2016 16:38:55 +0100 (BST) Received: from remus.metastack.local (remus.metastack.com [172.16.0.1]) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id u8DFcsOT030880; Tue, 13 Sep 2016 16:38:54 +0100 Received: from Remus.metastack.local ([fe80::547c:3c42:e1da:eda2]) by Remus.metastack.local ([fe80::547c:3c42:e1da:eda2%10]) with mapi id 14.03.0301.000; Tue, 13 Sep 2016 16:38:54 +0100 From: David Allsopp To: =?koi8-r?B?4c7E0sXKIOLF0sfNwc4=?= , "caml-list@inria.fr" Thread-Topic: [Caml-list] type-safe printf Thread-Index: AQHSDdJHl9vTiQ3Hy0G/Tr1D5JYhWqB3ipVA Date: Tue, 13 Sep 2016 15:38:53 +0000 Message-ID: References: <337861473779549@web6h.yandex.ru> In-Reply-To: <337861473779549@web6h.yandex.ru> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.16.0.18] Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Organization: MetaStack Solutions Ltd. X-Scanned-By: MIMEDefang 2.65 on 172.16.0.20 X-Server-Quench: 2e4f48d1-79c8-11e6-bcde-0015176ca198 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCd1ZAARAlZZVg1f DC4bFwdFRBksPQFF ChxFJgxfNl8UURhQ KkJXbgASJgRHAmpU Q3kJW1VSQFx3U2B9 YQ9UIwdcYVRPXwB0 UklLXFNTEBpqBAMA SFsWJm8hM10SeH5x YUdmEHRcWkI0dxN5 FEpcQWwbYm4zYH0e URVealEHJFZXfh9E b1F4UiBcYGwPKBgV TUcAFDk0OXBbKT9J d0kRPEofBF0CEDN0 XwoDGykhdQAA X-Authentic-SMTP: 61633634383431.1038:706 X-AuthFastPath: 0 (Was 255) X-AuthSMTP-Origin: 213.105.212.114/25 X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. Subject: RE: [Caml-list] type-safe printf =E1=CE=C4=D2=C5=CA =E2=C5=D2=C7=CD=C1=CE wrote:=20 > is there a good article or just short explanation how compile-type > checking of Printf arguments works? > > > Does it require special compiler support like in C++ compilers/analyzers, > or one can somehow do the trick of parsing string literal using Ocaml > language itself? (actually latter does not look possible to me) It does require a certain amount of special support, yes - see the Pexp_con= stant(Pconst_string _) case in typing/typecore.ml, in particular the commen= t "Terrible hack for format strings"! In essence, a string is "magically" i= nterpreted as a format string if it is used in a context where one would be= expected (e.g. the usual Printf.printf). It's one of the reasons Pervasive= s.format_of_string exists (because they're type- rather than syntax-driven). >From that point onwards, it's a lot of GADTs, but doesn't require any speci= al language support! If you were adding Printf to OCaml for the first time now, you'd probably u= se quoted string literals instead (see http://caml.inria.fr/pub/docs/manual= -ocaml/extn.html#sec249) - and the entire thing would then be in OCaml with= no special case hacks. David