caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] monomorphic restriction or typing/scanf bug?
@ 2002-10-15  3:29 Chris Hecker
  2002-10-15  3:51 ` Jacques Garrigue
  2002-10-15 12:19 ` Pierre Weis
  0 siblings, 2 replies; 7+ messages in thread
From: Chris Hecker @ 2002-10-15  3:29 UTC (permalink / raw)
  To: caml-list


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.

Chris


type t =
    Foo of int
  | Bar of int * int 

exception FB of t


(* works *)
let scan s (fmt : ('a, Scanf.Scanning.scanbuf, 'b) format) f =
  try
    raise (FB (Scanf.sscanf s fmt f))
  with
    End_of_file | Scanf.Scan_failure _ -> ()

let test () =
  let line = "Foo 1" 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

(* doesn't work *)
let test2 () =
  let line = "Foo 1" in
  let scan s (fmt : ('a, Scanf.Scanning.scanbuf, 'b) 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

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


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

end of thread, other threads:[~2002-10-16  6:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-15  3:29 [Caml-list] monomorphic restriction or typing/scanf bug? Chris Hecker
2002-10-15  3:51 ` Jacques Garrigue
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

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