From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id C8CD67ED26 for ; Mon, 4 Jun 2012 21:11:04 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkMBAPYHzU/RVdU2kGdsb2JhbABFo1iHYAGIbggiAQEBAQkJDQcUBCOCGAEBAQMBEgITGQEbEgsBAwELBgUEBxohIQEBEQEFAQoSBhMSEIdaAQMGBQuYVgkDjCKCcIRKChknAwpXiHEBBQyKJWCGEAOVG4EPiBGBW4MePoQB X-IronPort-AV: E=Sophos;i="4.75,714,1330902000"; d="scan'208";a="146537146" Received: from mail-yw0-f54.google.com ([209.85.213.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-MD5; 04 Jun 2012 21:11:04 +0200 Received: by yhgm50 with SMTP id m50so4858001yhg.27 for ; Mon, 04 Jun 2012 12:11:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=y3NEHuIH9EPJ9DMHkmODJkiN2Yv7oZygoXNJIB3c0dA=; b=mJ8/9d2sOduEMfd+DC0hE3U6dRt+mZdaAUKfdfc7rqdwCyGGO7aEmiyiYFSErgV28g 1nt6B+HbLf6aFkmXcSyq8TqyqYCwKMQhfOLaLhbwvJOlITV+4GqjHMv6tZZ/TNx42oBj hIsSAu5wX1UGkvm+1YL+45q8DNYsVb7UthGpRjxT1LnMCkIVBCHdPbgFxyKYatw/KJGR X3au5vf52BJ8o/NjPNO8s5fEY+K93RLKH/wnJd8IlzkriGnsVQI86XkULdTKqa1hqCh+ 65qIk+piSeVArQ+umjlBaYHQQy7kTGcHfnJEO811v4Hb6RjX25uF8XdoRe0CrXc2Qam8 +m0A== Received: by 10.50.237.71 with SMTP id va7mr8304373igc.6.1338837062801; Mon, 04 Jun 2012 12:11:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.94.39 with HTTP; Mon, 4 Jun 2012 12:10:22 -0700 (PDT) In-Reply-To: References: From: Gabriel Scherer Date: Mon, 4 Jun 2012 21:10:22 +0200 Message-ID: To: Diego Olivier Fernandez Pons Cc: caml-list Content-Type: multipart/alternative; boundary=f46d0447a2438a596a04c1aa4b4e Subject: Re: [Caml-list] Puzzled by Scanf.Scanning.in_channel --f46d0447a2438a596a04c1aa4b4e Content-Type: text/plain; charset=ISO-8859-1 You should use bscanf: # Scanf.fscanf;; - : in_channel -> ('a, 'b, 'c, 'd) Scanf.scanner = # Scanf.bscanf;; - : Scanf.Scanning.in_channel -> ('a, 'b, 'c, 'd) Scanf.scanner = On Mon, Jun 4, 2012 at 8:59 PM, Diego Olivier Fernandez Pons < dofp.ocaml@gmail.com> wrote: > Caml-List, > > When I try to use Scanf.fscanf with an input channel created with > Scanf.Scanning.from_string the type checker complains > > let s = Scanf.Scanning.from_string "3" in Scanf.fscanf s "%i" (fun x -> > x);; > > Characters 55-56: > Error: This expression has type Scanf.Scanning.in_channel > but an expression was expected of type in_channel > > Which confuses me as from the manual I understood this should have worked. > > val from_string : string -> in_channel > > Scanning.from_string s returns a formatted input channel which > reads from the given string. Reading starts from the first character > in the string. The end-of-input condition is set when the end of the > string is reached. > > Could anyone explain how is the proper way to generate a input channel > from a string ? Its for testing a program that will use stdin in > production. > > Diego Olivier > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa-roc.inria.fr/wws/info/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > > --f46d0447a2438a596a04c1aa4b4e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable You should use bscanf:

# Scanf.fscanf;;
- : in_channel -> (= 9;a, 'b, 'c, 'd) Scanf.scanner =3D <fun>
# Scanf.bscan= f;;
- : Scanf.Scanning.in_channel -> ('a, 'b, 'c, 'd) Scanf.= scanner =3D <fun>


On Mon, Jun 4, 2012 at 8:59 PM, Diego Ol= ivier Fernandez Pons <dofp.ocaml@gmail.com> wrote:
=A0 =A0Caml-List,

When I try to use Scanf.fscanf with an input channel created with
Scanf.Scanning.from_string the type checker complains

=A0 =A0let s =3D Scanf.Scanning.from_string "3" in Scanf.fscanf = s "%i" (fun x -> x);;

=A0 =A0Characters 55-56:
=A0 =A0Error: This expression has type Scanf.Scanning.in_channel
=A0 =A0 =A0 but an expression was expected of type in_channel

Which confuses me as from the manual I understood this should have worked.<= br>
=A0 =A0val from_string : string -> in_channel

=A0 =A0Scanning.from_string s returns a formatted input channel which
reads from the given string. Reading starts from the first character
in the string. The end-of-input condition is set when the end of the
string is reached.

Could anyone explain how is the proper way to generate a input channel
from a string ? Its for testing a program that will use stdin in
production.

=A0 =A0 =A0 =A0Diego Olivier

--
Caml-list mailing list. =A0Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


--f46d0447a2438a596a04c1aa4b4e--