English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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" Foo.read id