Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2007-02-16 (16:28)
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 =
    type t = int
    let print ppf =  fprintf "%d"

printf "My %a" Foo.print some_foo

But how do I get the same abstraction with scanf?

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

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