Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Martin Elsman <mael@id.dth.dk>
To: caml-list@margaux.inria.fr
Cc: mael@idfs3.id.dth.dk
Subject: The unsound type checker of Caml Light.
Date: Sat, 19 Mar 94 17:57:34 +0100	[thread overview]
Message-ID: <199403191657.RAA08113@idfs3.id.dth.dk> (raw)

Dear caml-list listeners,

After having studied Xavier's thesis it is obvious that the type-
checker of Caml Light is NOT sound. (There are problems with
references hidden in 'functional objects' (closures).

The following example shows how the type system can be brought
to failure:

The function:  

	let functional_ref = fun x ->
	    let r = ref x
	    in (fun () -> !r), (fun y -> r := y);;

is well typed in Caml Light and has the type

	functional_ref : 'a -> (unit -> 'a) * ('a -> unit) = <fun>

Let us define

	let (read, write) = functional_ref(fun x -> x);;

and the following types are infered

	write : ('a -> 'a) -> unit = <fun>
	read : unit -> 'a -> 'a = <fun>

We can now make a function that adds 1 to the reference:

	write(fun n -> n+1);;

Now the type checker fails:

	#if read()(true) then 1 else 3;;
	- : int = 3
	#read()(true);;
	- : bool = false
	#read()(23);;
	- : int = 24
	#read()(false);;
	- : bool = false

If a datatype is created we can add 1 to one of its constructors!!!:

	#type t = A | B of int * int;;
	Type t defined.

	#read()(A);;
	- : t = A
	#read()(B(5,6));;
	- : t = A

I know that its possible to solve this problem (the answer is given
in chapter 3 and 4 in Xavier's thesis).

Has anybody implemented such a sound type checker for Caml Light.

Best regards,

Martin Elsman




             reply	other threads:[~1994-03-21 16:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-03-19 16:57 Martin Elsman [this message]
1994-03-19 20:31 ` Pierre Weis

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=199403191657.RAA08113@idfs3.id.dth.dk \
    --to=mael@id.dth.dk \
    --cc=caml-list@margaux.inria.fr \
    --cc=mael@idfs3.id.dth.dk \
    /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