Version française
Home     About     Download     Resources     Contact us    
Browse thread
Scanf question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Sasha Rush <rush@f...>
Subject: Scanf question
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