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 645E37F6CB for ; Tue, 10 Feb 2015 03:47:20 +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.45; 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.45 as permitted sender) identity=mailfrom; client-ip=74.125.82.45; 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-wg0-f45.google.com) identity=helo; client-ip=74.125.82.45; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="jpathy@fssrv.net"; x-sender="postmaster@mail-wg0-f45.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0B8AgC4cNlUmy1SfUpchDIEgn6/coV7AoEVB0MBAQEBAQEQAQEBAQEGCwsJFC6EDQEBBAECDxEEGQEBJRIBDwsLAwoCAiYCAiISAQUBHAYTGgiIC6l5PjGKPnCEYgEFkhIBAQEBAQUBAQEBARcGCoEXjlYHgmiBQgGKK44ggRiOGoF0EiOBFYIhH4FxHTGCQgEBAQ X-IPAS-Result: A0B8AgC4cNlUmy1SfUpchDIEgn6/coV7AoEVB0MBAQEBAQEQAQEBAQEGCwsJFC6EDQEBBAECDxEEGQEBJRIBDwsLAwoCAiYCAiISAQUBHAYTGgiIC6l5PjGKPnCEYgEFkhIBAQEBAQUBAQEBARcGCoEXjlYHgmiBQgGKK44ggRiOGoF0EiOBFYIhH4FxHTGCQgEBAQ X-IronPort-AV: E=Sophos;i="5.09,547,1418079600"; d="scan'208";a="99478129" Received: from mail-wg0-f45.google.com ([74.125.82.45]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 10 Feb 2015 03:47:19 +0100 Received: by mail-wg0-f45.google.com with SMTP id x12so30553975wgg.4 for ; Mon, 09 Feb 2015 18:47:19 -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=Jqm4LPizsUUM2uPFJ0nJJHU+nZ4GOSx6YLB/f8iB3SI=; b=f9Bh/X3n2ZGatxLTEWnZ3vUlh7o3MRF9eKNcub0bAFpvCaweLs9wDA6QJFgg/BG/q3 0WPFv3gs+YOrFwxa9nmNrXgGraixSFSsR6f9S3+1x6IRN4mSliYSIUfXQjeCS8kojBzt QwcWg3x7LKriMrwe1YIbJyaDPvJI/aeZ1+JEA= 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=Jqm4LPizsUUM2uPFJ0nJJHU+nZ4GOSx6YLB/f8iB3SI=; b=ehsuwvM4b7lWYB36qJn/v/Oc1nuJJqRVm8HDmawwOLEXGjejEK5K8ZNY+7tH7eYjZn HNRyP3BKfzaWre7W/nTmPu0MQyZH8Vc+2HNJukIJDMub4yDueagwp2XkXfjwMXkM5oc1 9LQhP2kRy28ngztVorEJkQcqxfWA0UIuLDDIcekhxyShiv19rKMH3QhtXD7FeFNYQTEc DO5KLE5LnXMWm2A4KMjMMApexCzQI9SBQ7xyLH2JK20pseyAcbbnwI3S/J4b+i+CudGY 3OgnpqRhQvMMV5ohVw/9GmWAaJR1Ekfkmhou4Bp/hNh1Clb6DayBkAqMOrmrYwHbzfzG 8Vcw== X-Gm-Message-State: ALoCoQlGyBmLSxtEnwWhzcI83S01FxTdcnnkapQ2hvWbs2n5c59ih8hI5pnNcD3YvoJSxYnJmaRn MIME-Version: 1.0 X-Received: by 10.194.110.137 with SMTP id ia9mr48219935wjb.153.1423536439243; Mon, 09 Feb 2015 18:47:19 -0800 (PST) Received: by 10.27.226.67 with HTTP; Mon, 9 Feb 2015 18:47:19 -0800 (PST) In-Reply-To: References: Date: Mon, 9 Feb 2015 18:47:19 -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 nvm. make_printf is what I am after. Some complicated stuff is going on in CamlInternalFormat. On Mon, Feb 9, 2015 at 5:05 PM, Jiten Pathy wrote: > 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