caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Dominique Martinet <asmadeus77@gmail.com>
To: Francois BERENGER <berenger.francois.724@m.kyushu-u.ac.jp>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Strange online ocamldoc for Scanf
Date: Tue, 4 Sep 2018 10:14:18 +0200	[thread overview]
Message-ID: <20180904081418.GA14131@nautica> (raw)
In-Reply-To: <903e65e7-61b2-f18d-9c39-09757f1ca7f4@m.kyushu-u.ac.jp>

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

      reply	other threads:[~2018-09-04  8:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-04  6:05 Francois BERENGER
2018-09-04  6:22 ` Dominique Martinet
2018-09-04  7:45   ` Francois BERENGER
2018-09-04  8:14     ` Dominique Martinet [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180904081418.GA14131@nautica \
    --to=asmadeus77@gmail.com \
    --cc=berenger.francois.724@m.kyushu-u.ac.jp \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).