Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* [Caml-list] Typing trouble with PXP
@ 2002-04-03 13:00 Artem Prisyaznuk
  2002-04-03 20:59 ` Gerd Stolpmann
  0 siblings, 1 reply; 2+ messages in thread
From: Artem Prisyaznuk @ 2002-04-03 13:00 UTC (permalink / raw)
  To: caml-list


The problem is summarized in the following code:

	open Pxp_yacc;;

	let rec foo_fun node=
		node#write (`Out_channel stderr) `Enc_koi8r;;
	let  _ =
		let doc = parse_wfdocument_entity default_config (from_file "my.xml") default_spec in
		let root = doc#root in
		begin
				root#write (`Out_channel stderr) `Enc_koi8r;
				foo_fun root    
		end;;

This example doesn't compile and the compiler error message is:

	File "tmp.ml", line 10, characters 11-15:
	This expression has type
	  (('a Pxp_document.node as 'b) Pxp_document.extension as 'a)
	  Pxp_document.node =
		< add_node : ?force:bool -> 'b -> unit;
		  ........skip........
		  write : ?prefixes:string list ->
				  ?default:string ->
				  Pxp_types.output_stream -> Pxp_types.encoding -> unit >
	but is here used with type
	  < add_node : ?force:bool -> 'b -> unit;
		..........skip.............
		write : [> `Out_channel of out_channel] -> [> `Enc_koi8r] -> 'c >

-- 
Best regards
Artem Prisyaznuk
tema@sit.kiev.ua
-------------------
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] 2+ messages in thread

* Re: [Caml-list] Typing trouble with PXP
  2002-04-03 13:00 [Caml-list] Typing trouble with PXP Artem Prisyaznuk
@ 2002-04-03 20:59 ` Gerd Stolpmann
  0 siblings, 0 replies; 2+ messages in thread
From: Gerd Stolpmann @ 2002-04-03 20:59 UTC (permalink / raw)
  To: Artem Prisyaznuk; +Cc: caml-list

Hi,
On 2002.04.03 15:00 Artem Prisyaznuk wrote:
> 
> The problem is summarized in the following code:
> 
> 	open Pxp_yacc;;
> 
> 	let rec foo_fun node=
> 		node#write (`Out_channel stderr) `Enc_koi8r;;
> 	let  _ =
> 		let doc = parse_wfdocument_entity default_config (from_file "my.xml") default_spec in
> 		let root = doc#root in
> 		begin
> 				root#write (`Out_channel stderr) `Enc_koi8r;
> 				foo_fun root    
> 		end;;
> 
> This example doesn't compile and the compiler error message is:
> 
> 	File "tmp.ml", line 10, characters 11-15:
> 	This expression has type
> 	  (('a Pxp_document.node as 'b) Pxp_document.extension as 'a)
> 	  Pxp_document.node =
> 		< add_node : ?force:bool -> 'b -> unit;
> 		  ........skip........
> 		  write : ?prefixes:string list ->
> 				  ?default:string ->
> 				  Pxp_types.output_stream -> Pxp_types.encoding -> unit >
> 	but is here used with type
> 	  < add_node : ?force:bool -> 'b -> unit;
> 		..........skip.............
> 		write : [> `Out_channel of out_channel] -> [> `Enc_koi8r] -> 'c >
> 

The missing optional arguments cause the type incompatibility. The "node" argument
of the "foo_fun" function gets a type that only depends on its usage, and I guess
it is

< write : [> `Out_channel of out_channel] -> [> `Enc_koi8r] -> 'c; ..> -> 'c

On the other hand, the type of the variable "root" depends on the result of
parse_wfdocument_entity, and thus is completely known. The method "write"
is typed _with_ the two optional arguments, but "foo_fun" is not.

The short form of this incompatibility is shown in the following example:

# let write1 ?x y = ();;
val write1 : ?x:'a -> 'b -> unit = <fun>
# let write2 y = ();;
val write2 : 'a -> unit = <fun>
# let do_something (write,x) = write x;;
val do_something : ('a -> 'b) * 'a -> 'b = <fun>
# do_something (write2,5);;
- : unit = ()
# do_something (write1,5);;
This expression has type (?x:'a -> 'b -> unit) * int
but is here used with type ('c -> 'd) * 'c

(The really interesting thing is that if I define do_something as
  # let do_something write x = write x;;
  val do_something : ('a -> 'b) -> 'a -> 'b = <fun>
_both_ applications are allowed, i.e. both expressions
do_something write1 5 and do_something write2 5 can be typed. I suppose
this case is handled by the type checker in a special way to simplify
the usage of labels.)

The solution: Change foo_fun such that there are the missing optional
arguments. You could do it by writing

let rec foo_fun node=
  node#write ?prefixes:None ?default:None (`Out_channel stderr) `Enc_koi8r;;

or, better, by

let rec foo_fun (node : 'ext Pxp_document.node) =
  node#write (`Out_channel stderr) `Enc_koi8r;;

I hope this helps,

Gerd
-- 
----------------------------------------------------------------------------
Gerd Stolpmann      Telefon: +49 6151 997705 (privat)
Viktoriastr. 45             
64293 Darmstadt     EMail:   gerd@gerd-stolpmann.de
Germany                     
----------------------------------------------------------------------------
-------------------
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] 2+ messages in thread

end of thread, other threads:[~2002-04-03 20:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-03 13:00 [Caml-list] Typing trouble with PXP Artem Prisyaznuk
2002-04-03 20:59 ` Gerd Stolpmann

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