caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: checker@d6.com
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] monomorphic restriction or typing/scanf bug?
Date: Tue, 15 Oct 2002 12:51:24 +0900	[thread overview]
Message-ID: <20021015125124J.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <200210150329.g9F3TAX26896@plinky.bolt-action.com>

From: Chris Hecker <checker@d6.com>

> The "scan" function in the code below works if it's at global scope,
> but not if it's defined inside the test2 function.  Is this a bug or a
> typing restriction?  I assume the latter (and that I could have boiled
> this example to one of the ones in the FAQ?), but I don't understand
> these kinds of polymorphism typing issues.

This is a known issue: named type variables inside an expression are
restricted to be monomorphic for the whole toplevel expression.  They
can only be generalized afterwards. (This is to ensure that two
identical variable names in an expression refer to the same variable)
The standard workaround is to use nameless ones.

> (* this works *)
> let test2 () =
>   let line = "Foo 1" in
>   let scan s (fmt : (_, Scanf.Scanning.scanbuf, _) format) f =
>     try
>       raise (FB (Scanf.sscanf s fmt f));
>       ()
>     with
>       End_of_file | Scanf.Scan_failure _ -> ()
>   in
>   try
>     scan line "Foo %d" (fun i -> Foo i);
>     scan line "Bar %d %d" (fun i j -> Bar (i,j));
>     failwith "bad line"
>   with
>     FB t -> t

Jacques Garrigue
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2002-10-15  3:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-15  3:29 Chris Hecker
2002-10-15  3:51 ` Jacques Garrigue [this message]
2002-10-15 12:19 ` Pierre Weis
2002-10-15 21:03   ` Chris Hecker
2002-10-15 21:20     ` Chris Hecker
     [not found]     ` <Pine.LNX.4.44.0210151424320.453-100000@grace.speakeasy.net >
2002-10-16  1:53       ` Chris Hecker
2002-10-16  6:42         ` [Caml-list] Local open (was: monomorphic restriction or typing/scanf bug?) Alain Frisch

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=20021015125124J.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=checker@d6.com \
    /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).