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 D4CBD7F6CB for ; Tue, 10 Feb 2015 02:05:53 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of jpathy@fssrv.net) identity=pra; client-ip=74.125.82.170; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="jpathy@fssrv.net"; x-sender="jpathy@fssrv.net"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of jpathy@fssrv.net designates 74.125.82.170 as permitted sender) identity=mailfrom; client-ip=74.125.82.170; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="jpathy@fssrv.net"; x-sender="jpathy@fssrv.net"; 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-we0-f170.google.com) identity=helo; client-ip=74.125.82.170; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="jpathy@fssrv.net"; x-sender="postmaster@mail-we0-f170.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CDAgDpV9lUlKpSfUpchDIEgn6/cYV7AoEXB0MBAQEBAQEQAQEBAQcLCwkSMIQNAQEEAQIPEQQZAQElEgEPCwsDCgICJgICIhIBBQEcBhMaCIgLqho+MYo+cIRiAQWRegEBAQEBBQEBAQEBFwYKgReOVgeCaIFCiiyOIIEYjhqBdBIjgRWCIR+BcR0xgkIBAQE X-IPAS-Result: A0CDAgDpV9lUlKpSfUpchDIEgn6/cYV7AoEXB0MBAQEBAQEQAQEBAQcLCwkSMIQNAQEEAQIPEQQZAQElEgEPCwsDCgICJgICIhIBBQEcBhMaCIgLqho+MYo+cIRiAQWRegEBAQEBBQEBAQEBFwYKgReOVgeCaIFCiiyOIIEYjhqBdBIjgRWCIR+BcR0xgkIBAQE X-IronPort-AV: E=Sophos;i="5.09,547,1418079600"; d="scan'208";a="99474491" Received: from mail-we0-f170.google.com ([74.125.82.170]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 10 Feb 2015 02:05:53 +0100 Received: by mail-we0-f170.google.com with SMTP id q59so21694691wes.1 for ; Mon, 09 Feb 2015 17:05:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fssrv.net; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=kzORai3Jcjvy4puSA8AdsdUbA9YdxYaPtwTY5hWMMTU=; b=j3ZgI8KjTbzDhJXjWfztKSYppeITIhwKWf5DneqhhLv2TY0fLtvfqVeEMmlLFbfx92 iFZ0xsLT1y522MxH0FRKa8y1Xl25Uff2CCK9MhFvsgCsJDPHJc5tf0WKoN/D9wUZciRZ RpdfjtICsrJTrSB/hFR5wA/V3jP1wQTcIVNTM= 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=kzORai3Jcjvy4puSA8AdsdUbA9YdxYaPtwTY5hWMMTU=; b=INB3yh+BIgAiDXgCSj4FF7uMUQbEK9FN5jRrCSM8DaDDBf2Xfjc9lJuzQiZZVEXnCQ vyvbXR+JWlEkAr6oj3YfYZbdba948+v3fll4uPVx76idjekrm7yBaqcEUgyPrU7rF+NF LipYtdfX+AmHRK0lCTNKR7o8CX8EqyYuxSmmVZvzVWODSt3YybmPvSrsNoKz3jt/uEj/ Y8LGvb8Dlg5CIW2PnINCYYtq8NfNuGfT68HqwEpfovav2PlSZRm401FfZ1VusCOV95Pm qkVhhcjRn6m/B6gN0DpRlAYoKBWJZo2Yavh13gCLXmLdwdG4xRne0Mz0I8y5FYUVn2af CLYQ== X-Gm-Message-State: ALoCoQntiLb7HXXW7Zv4LySRfDMI8s2kiN2rkduxYwxnHB9UD2Tp/K+qssSjQ5Iwo2mjqWOBm9gY MIME-Version: 1.0 X-Received: by 10.180.95.162 with SMTP id dl2mr41156240wib.31.1423530352461; Mon, 09 Feb 2015 17:05:52 -0800 (PST) Received: by 10.27.226.67 with HTTP; Mon, 9 Feb 2015 17:05:52 -0800 (PST) In-Reply-To: References: Date: Mon, 9 Feb 2015 17:05:52 -0800 Message-ID: From: Jiten Pathy To: David Allsopp Cc: "caml-list@inria.fr" Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] format strings Is there a way I can define a function which has the same signature of printf family but is a no-op? f : ('a, 'b, unit) format -> 'a assert(f "%s %d" "hello" 1 = ());; On Mon, Feb 9, 2015 at 9:32 AM, David Allsopp wrote: > Jiten Pathy wrote: >> When i define a wrapper around format functions like >> >> let f s = (fun x -> Printf.sprintf s x);; >> >> val f : ('a -> 'b, unit, bytes) format -> 'a -> 'b = >> >> I am confused about the inferred type. where does this 'b comes from? > > Your wrapper carries the requirement that the format [s] must have at least one %-parameter. Writing without the fun might make this more obvious: > > let f s x = Printf.sprintf s x > > The 'a -> 'b is the encoding of this requirement. f "foo" will type. If instead you wrote: > > let f s = Printf.sprintf s > > you'd get the type you're expecting: ('a, unit, bytes) format -> 'a > > and you can have format strings with no %-parameters (so f "foo" now types). If you meant to have it so that the format string must have *exactly* one %-parameter then you need an annotation: > > let f s x : string = Printf.sprintf s x > > and now f "%d" will type, but f "%s %d" will not. > > HTH, > > > David