caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Strange online ocamldoc for Scanf
@ 2018-09-04  6:05 Francois BERENGER
  2018-09-04  6:22 ` Dominique Martinet
  0 siblings, 1 reply; 4+ messages in thread
From: Francois BERENGER @ 2018-09-04  6:05 UTC (permalink / raw)
  To: caml-list

Hello,

It seems type signatures are truncated.

For example in:
https://caml.inria.fr/pub/docs/manual-ocaml/libref/Scanf.html

val sscanf : string -> ('a, 'b, 'c, 'd) scanner

I would expect sscanf to take three arguments, not one.

Is there a problem with the ocamldoc for this module, or am I
not reading the type signature correctly?

I know there was some work on Scanf recently.
I wonder if it broke the ocamldoc.

Thanks,
F.

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

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

* Re: [Caml-list] Strange online ocamldoc for Scanf
  2018-09-04  6:05 [Caml-list] Strange online ocamldoc for Scanf Francois BERENGER
@ 2018-09-04  6:22 ` Dominique Martinet
  2018-09-04  7:45   ` Francois BERENGER
  0 siblings, 1 reply; 4+ messages in thread
From: Dominique Martinet @ 2018-09-04  6:22 UTC (permalink / raw)
  To: Francois BERENGER; +Cc: caml-list

Francois BERENGER wrote on Tue, Sep 04, 2018:
> It seems type signatures are truncated.
> 
> For example in:
> https://caml.inria.fr/pub/docs/manual-ocaml/libref/Scanf.html
> 
> val sscanf : string -> ('a, 'b, 'c, 'd) scanner
> 
> I would expect sscanf to take three arguments, not one.

The documentation is correct (and you also are correct that sscanf takes
three arguments, but...)

('a, 'b, 'c, 'd) scanner is itself a function taking two arguments, as
defined a bit later in the page:

type ('a, 'b, 'c, 'd) scanner = ('a, Scanning.in_channel, 'b, 'c, 'a -> 'd, 'd) format6 ->
       'c


Basically, to use the example on the page with sscanf "x = 1" "%s = %i" f,
sscanf "x = 1" return a scanner to which you can apply a pattern and a
function - ultimately that is three arguments as you describe, but
thanks to currying after applying one argument you get anther function.

This is useful because basically you do not care if the scanner comes
from 'sscanf "x = 1"' or 'scanf' or 'bscanf some_channel' -- all three
are equivalent scanners


Cheers,
-- 
Dominique Martinet | Asmadeus
(what am I doing here?)

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

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

* Re: [Caml-list] Strange online ocamldoc for Scanf
  2018-09-04  6:22 ` Dominique Martinet
@ 2018-09-04  7:45   ` Francois BERENGER
  2018-09-04  8:14     ` Dominique Martinet
  0 siblings, 1 reply; 4+ messages in thread
From: Francois BERENGER @ 2018-09-04  7:45 UTC (permalink / raw)
  To: caml-list

On 09/04/2018 03:22 PM, Dominique Martinet wrote:
> Francois BERENGER wrote on Tue, Sep 04, 2018:
>> It seems type signatures are truncated.
>>
>> For example in:
>> https://caml.inria.fr/pub/docs/manual-ocaml/libref/Scanf.html
>>
>> val sscanf : string -> ('a, 'b, 'c, 'd) scanner
>>
>> I would expect sscanf to take three arguments, not one.
> 
> The documentation is correct (and you also are correct that sscanf takes
> three arguments, but...)
> 
> ('a, 'b, 'c, 'd) scanner is itself a function taking two arguments, as
> defined a bit later in the page:
> 
> type ('a, 'b, 'c, 'd) scanner = ('a, Scanning.in_channel, 'b, 'c, 'a -> 'd, 'd) format6 ->
>        'c

Ok, my mistake.

I have to admit that I don't understand such a (lengthy) type
definition, probably because I don't read such ones very often.

> Basically, to use the example on the page with sscanf "x = 1" "%s = %i" f,
> sscanf "x = 1" return a scanner to which you can apply a pattern and a
> function - ultimately that is three arguments as you describe, but
> thanks to currying after applying one argument you get anther function.
> 
> This is useful because basically you do not care if the scanner comes
> from 'sscanf "x = 1"' or 'scanf' or 'bscanf some_channel' -- all three
> are equivalent scanners
> 
> 
> Cheers,
> 

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

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

* Re: [Caml-list] Strange online ocamldoc for Scanf
  2018-09-04  7:45   ` Francois BERENGER
@ 2018-09-04  8:14     ` Dominique Martinet
  0 siblings, 0 replies; 4+ messages in thread
From: Dominique Martinet @ 2018-09-04  8:14 UTC (permalink / raw)
  To: Francois BERENGER; +Cc: caml-list

Francois BERENGER wrote on Tue, Sep 04, 2018:
> > ('a, 'b, 'c, 'd) scanner is itself a function taking two arguments, as
> > defined a bit later in the page:
> > 
> > type ('a, 'b, 'c, 'd) scanner = ('a, Scanning.in_channel, 'b, 'c, 'a -> 'd, 'd) format6 ->
> >        'c
> 
> Ok, my mistake.
> 
> I have to admit that I don't understand such a (lengthy) type
> definition, probably because I don't read such ones very often.

Well, to be fair, it doesn't say "two arguments" here -- 'c happens to
be a function itself...

What's important is there is an arrow (->) in the type definition so a
scanner is a function, and which can return any type 'c when given a
format, so depending on what you give it you'll get something else.


I think it's interesting to play with it in the toplevel:

# open Scanf;;
# Scanf.sscanf;;
- : string -> ('a, 'b, 'c, 'd) Scanf.scanner = <fun>
# let s = Scanf.sscanf "15" "%d";;  
val s : (int -> '_weak1) -> '_weak1 = <fun>
# s (fun d -> "something");;
- : string = "something"
# s;;
- : (int -> string) -> string = <fun>


So when I first assigned 's' I got a function, which takes in argument a
function expecting and int and returning "something"
The '_weak1 here is like 'a except that it "solidifies" on first use,
as you can see after calling 's' with a function once it will expect
that all further use of 's' will be with a string-returning function


Good luck,
-- 
Dominique

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

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

end of thread, other threads:[~2018-09-04  8:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-04  6:05 [Caml-list] Strange online ocamldoc for Scanf Francois BERENGER
2018-09-04  6:22 ` Dominique Martinet
2018-09-04  7:45   ` Francois BERENGER
2018-09-04  8:14     ` Dominique Martinet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).