caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Nicolas Pouillard <nicolas.pouillard@gmail.com>
To: Julien SIGNOLES <julien.signoles@cea.fr>
Cc: Matthieu Wipliez <mwipliez@yahoo.fr>, caml-list <caml-list@inria.fr>
Subject: Re: Re : [Caml-list] Warning wished
Date: Wed, 28 Jan 2009 21:56:10 +0100	[thread overview]
Message-ID: <1233175897-sup-9607@ausone.local> (raw)
In-Reply-To: <1233152654.7199.227.camel@localhost>

Excerpts from Julien SIGNOLES's message of Wed Jan 28 15:24:14 +0100 2009:
> Le mercredi 28 janvier 2009 à 14:07 +0000, Matthieu Wipliez a écrit :
> > > Hello,
> > > 
> > > Is it a bug or a well-known feature that the above program does not emit
> > > a warning (because "f x" should have type unit in the body of "g") ?
> > > 
> > > =====
> > > let f x = x
> > > let g x = f x; 1
> > > (* let _ = g 2 *)
> > > ====
> > 
> > I'm not familiar with the internals of the compiler, but what I suppose is happening is that it tries to unify the type of "f x" and "unit", and this succeeds because "f x" has type 'a, which can be unified with anything. The meaning of "a;b" seems to be let _ = a in b rather than let () = a in b.
> > 
> > But like I said, these are suppositions.
> 
> Sure. However in my real case, I had an "ok" code like this :
> 
> let f x : 'a -> unit = ...
> let g x =
>   f x;
>   x
> 
> I changed a little bit the specification of f :
> 
> let f x : 'a -> 'a = ...
> 
> I just expected that caml helps me to find all the instances where I had
> to take care of this specification change. Such a thing is one of the
> very good features of caml. Unfortunatly, in this case, caml did not
> help me while the old implementation of "g" became wrong with the new
> specification of "f" :-(.

That's because (let f x : 'a -> 'a = ...) is not a specification for a
polymorphic function, this is rather an existential quantification than a
universal one.

They are some ugly tricks to ensure a polymorphic function, like this one:

module M : sig
  val f : t -> 'a -> 'a
end = struct
  let f x = ...
end
include M

Best regards,

-- 
Nicolas Pouillard


  reply	other threads:[~2009-01-28 20:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-28 13:53 Julien SIGNOLES
2009-01-28 14:07 ` Re : [Caml-list] " Matthieu Wipliez
2009-01-28 14:24   ` Julien SIGNOLES
2009-01-28 20:56     ` Nicolas Pouillard [this message]
2009-01-28 14:10 ` Dmitri Boulytchev
2009-01-28 14:28   ` Julien SIGNOLES
2009-01-28 14:44     ` Dmitri Boulytchev
2009-01-28 18:29       ` Frédéric van der Plancke
2009-01-28 19:08         ` Dmitri Boulytchev
2009-01-28 16:55 ` Martin Jambon

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=1233175897-sup-9607@ausone.local \
    --to=nicolas.pouillard@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=julien.signoles@cea.fr \
    --cc=mwipliez@yahoo.fr \
    /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).