From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=AWL,HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id E7B56BC0A for ; Fri, 16 Feb 2007 17:28:28 +0100 (CET) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.230]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l1GGSQ76031591 for ; Fri, 16 Feb 2007 17:28:27 +0100 Received: by wr-out-0506.google.com with SMTP id 70so1132488wra for ; Fri, 16 Feb 2007 08:28:25 -0800 (PST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:mime-version:content-type:x-google-sender-auth; b=nZGcw4b0kmCw2RVNyZLXQUVbPr5mpBcQPz1p7MSSC1zVUqocer59tsgOoO6WFqjuadBgy/uddnN1RXvnrnFx3YCEOINANV43bU8/tO6UlYvca8FL6iegryN+VMKsmN3tAm8zPPQXZTLvIahfCdpXxlLDQ/EYZlN52sB6TufiiBg= Received: by 10.114.210.2 with SMTP id i2mr1867040wag.1171643302287; Fri, 16 Feb 2007 08:28:22 -0800 (PST) Received: by 10.114.39.18 with HTTP; Fri, 16 Feb 2007 08:28:22 -0800 (PST) Message-ID: Date: Fri, 16 Feb 2007 11:28:22 -0500 From: "Sasha Rush" Sender: sasha.rush@gmail.com To: caml-list@inria.fr Subject: Scanf question MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_5195_27126033.1171643302050" X-Google-Sender-Auth: 103aa430c53e0a06 X-Miltered: at discorde with ID 45D5DBAA.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; scanf:01 printf:01 scanf:01 foo:01 struct:01 ppf:01 fprintf:01 printf:01 foo:01 abstraction:01 struct:01 buf:01 ppf:01 fprintf:01 abstraction:01 ------=_Part_5195_27126033.1171643302050 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi all, I'm curious about the asymmetry between printf and scanf. I like the modularity I can get by user defined printers, i.e. module Foo = struct type t = int let print ppf = fprintf "%d" end printf "My %a" Foo.print some_foo But how do I get the same abstraction with scanf? let id a = a module Foo = struct type t = int let read buf = bscanf "%d" id end (*Seemed natural*) let some_foo = bscanf "My %a" Foo.read id Thanks, /Sasha ------=_Part_5195_27126033.1171643302050 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi all,

I'm curious about the asymmetry between printf and scanf.

I like the modularity I can get by user defined printers, i.e.

module Foo =
struct
    type t = int
    let print ppf =  fprintf "%d"
end

printf "My %a" Foo.print some_foo

But how do I get the same abstraction with scanf?

let id a = a
module Foo =
struct
   type t = int
   let read buf = bscanf "%d" id
end

(*Seemed natural*)
let some_foo = bscanf "My %a" Foo.read id


Thanks,
/Sasha
------=_Part_5195_27126033.1171643302050--