caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: skaller <skaller@users.sourceforge.net>
To: malc <malc@pulsesoft.com>
Cc: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>,
	caml-list@yquem.inria.fr
Subject: Re: [Caml-list] partial application warning unreliable?
Date: Fri, 09 Dec 2005 12:43:31 +1100	[thread overview]
Message-ID: <1134092611.8940.57.camel@rosella> (raw)
In-Reply-To: <Pine.LNX.4.61.0512090248240.2158@home.oyster.ru>

On Fri, 2005-12-09 at 02:51 +0300, malc wrote:
> On Thu, 8 Dec 2005, Jacques Garrigue wrote:
> 
> <snip>
> >
> > # class cc = object (self)
> >    method f x y = x + y
> >    method g () = self#f 1;
> >  end;;
> > class cc :
> >  object method f : int -> int -> int method g : unit -> int -> int end
> >
> > No warning, for the reason stated above: the semicolon does nothing.
> 
> Here's a strange test case, i was bitten by it recently in a real code:
> 
> <mox.ml>
> let y o =
>    o#moo;
>    1
> 
> let x (o:(<moo : string -> unit>)) =
>    y o
> 
> let _ =
>    print_int (x (object method moo s = print_endline s end));
>    print_newline ()
> </mox.ml>
> 
> # ocaml -warn-error A mox.ml
> 1
> 
> In my case method moo was actually a method that locked a mutex, the
> implications were quite severe.

AHA. In trying to fill out your problem to a real test case
for a bug report .. I think I have discovered the problem!

# class cow = object(self) method moo (s:string)= print_endline s
  end;;
class cow : object method moo : string -> unit end

# let y o = o#moo; 1;;
val y : < moo : 'a; .. > -> int = <fun>

And there we have it .. an uncaught partial application!

The reason is clear .. we don't know the arity of the
function yet -- we don't even know its type.

The type of a statement is currently 'a, which is just 
plain wrong. The correct type is void, however unit
will catch more errors than 'a.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


  reply	other threads:[~2005-12-09  1:43 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-08  2:39 skaller
2005-12-08  3:10 ` [Caml-list] " Jacques Garrigue
2005-12-08  7:11   ` skaller
2005-12-08 14:41     ` Damien Doligez
2005-12-08 23:51   ` malc
2005-12-09  1:43     ` skaller [this message]
2005-12-09  2:15       ` Jacques Garrigue
2005-12-09  2:56         ` skaller
2005-12-09 15:26         ` malc
2005-12-10  0:49           ` Jacques Garrigue
2005-12-10  1:40             ` malc
2005-12-09 12:21       ` Andreas Rossberg
2005-12-09 17:17         ` skaller
2005-12-09 17:52           ` Andrej Bauer
2005-12-09 18:54           ` Andreas Rossberg

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=1134092611.8940.57.camel@rosella \
    --to=skaller@users.sourceforge.net \
    --cc=caml-list@yquem.inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    --cc=malc@pulsesoft.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).