Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] Puzzled by Scanf.Scanning.in_channel
@ 2012-06-04 18:59 Diego Olivier Fernandez Pons
  2012-06-04 19:10 ` Gabriel Scherer
  0 siblings, 1 reply; 4+ messages in thread
From: Diego Olivier Fernandez Pons @ 2012-06-04 18:59 UTC (permalink / raw)
  To: caml-list

    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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Puzzled by Scanf.Scanning.in_channel
  2012-06-04 18:59 [Caml-list] Puzzled by Scanf.Scanning.in_channel Diego Olivier Fernandez Pons
@ 2012-06-04 19:10 ` Gabriel Scherer
  2012-06-04 19:12   ` Diego Olivier Fernandez Pons
  0 siblings, 1 reply; 4+ messages in thread
From: Gabriel Scherer @ 2012-06-04 19:10 UTC (permalink / raw)
  To: Diego Olivier Fernandez Pons; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1434 bytes --]

You should use bscanf:

# Scanf.fscanf;;
- : in_channel -> ('a, 'b, 'c, 'd) Scanf.scanner = <fun>
# Scanf.bscanf;;
- : Scanf.Scanning.in_channel -> ('a, 'b, 'c, 'd) Scanf.scanner = <fun>


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
>
>

[-- Attachment #2: Type: text/html, Size: 2170 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Puzzled by Scanf.Scanning.in_channel
  2012-06-04 19:10 ` Gabriel Scherer
@ 2012-06-04 19:12   ` Diego Olivier Fernandez Pons
  2012-06-05  8:53     ` Goswin von Brederlow
  0 siblings, 1 reply; 4+ messages in thread
From: Diego Olivier Fernandez Pons @ 2012-06-04 19:12 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: caml-list

    Gabriel,

> You should use bscanf:
>
> # Scanf.fscanf;;
> - : in_channel -> ('a, 'b, 'c, 'd) Scanf.scanner = <fun>
> # Scanf.bscanf;;
> - : Scanf.Scanning.in_channel -> ('a, 'b, 'c, 'd) Scanf.scanner = <fun>

Thanks. My I ask what is the difference between in_channel and
Scanf.Scanning.in_channel ?

        Diego Olivier

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Puzzled by Scanf.Scanning.in_channel
  2012-06-04 19:12   ` Diego Olivier Fernandez Pons
@ 2012-06-05  8:53     ` Goswin von Brederlow
  0 siblings, 0 replies; 4+ messages in thread
From: Goswin von Brederlow @ 2012-06-05  8:53 UTC (permalink / raw)
  To: Diego Olivier Fernandez Pons; +Cc: Gabriel Scherer, caml-list

Diego Olivier Fernandez Pons <dofp.ocaml@gmail.com> writes:

>     Gabriel,
>
>> You should use bscanf:
>>
>> # Scanf.fscanf;;
>> - : in_channel -> ('a, 'b, 'c, 'd) Scanf.scanner = <fun>
>> # Scanf.bscanf;;
>> - : Scanf.Scanning.in_channel -> ('a, 'b, 'c, 'd) Scanf.scanner = <fun>
>
> Thanks. My I ask what is the difference between in_channel and
> Scanf.Scanning.in_channel ?
>
>         Diego Olivier

Well, one is an in_channel and one is a Scanf.Scanning.in_channel. :)

You can look at the type definition of both of them in the source to see
the specific differences and similarities.

MfG
        Goswin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-06-05  8:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-04 18:59 [Caml-list] Puzzled by Scanf.Scanning.in_channel Diego Olivier Fernandez Pons
2012-06-04 19:10 ` Gabriel Scherer
2012-06-04 19:12   ` Diego Olivier Fernandez Pons
2012-06-05  8:53     ` Goswin von Brederlow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox