caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: mattias.waldau@abc.se, max@sbuilders.com
Cc: caml-list@inria.fr
Subject: RE: Typing problems when using LablGTK
Date: Tue, 06 Feb 2001 10:58:06 +0900	[thread overview]
Message-ID: <20010206105806K.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <AAEBJHFJOIPMMIILCEPBCEFPCEAA.mattias.waldau@abc.se>

From: "Mattias Waldau" <mattias.waldau@abc.se>

> I also noted that typing the argument solved the problem. 
> 
> But why can't the typechecking complain if there is more than one 
> typing possible? The current algorithm seems to take the first
> solution found and keep that. 

This is not a completely arbitrary solution. This is the solution that
would be choosen if there were no optional arguments in the language.
A better solution would require some kind of whole program analysis,
to see on which function mini is applied, a bit of an overkill for a
rather exceptional problem.

> Couldn't it instead say, "Ambiguous typing"?

Unfortunately, no. Since any function may have optional arguments, all
function calls are in essence ambiguous. Still, what is ambiguous is
only the typing, the semantics is defined independently of types, and
guaranteed to be the same with or without type annotations. The worst
thing that may happen is that your program wouldn't be accepted by the
type checker.

From: Maxence <max@sbuilders.com>

> let feeling = f (ctx :> <get_string : string -> string>)
> 
> ocaml complains about the coercion of ctx :
> This expression cannot be coerced to type < get_string : string ->
> string >;
> it has type context = < get_string : ?default:string -> string -> string
> >
> but is here used with type < get_string : string -> string >
> 
> The question is : why is this coercion not allowed ?

The question is : how do you compile it. Since ?default:string ->
string -> string and string -> string correspond to incompatible
internal representations, one would have to build a new class with the
expected type, and masquerade ctx as an object of this class. This
seems to be too much work and too costly for something that can be
solved by a single type annotation.

The only case in which such a conversion is currently done is when you
pass a function with optional arguments as parameter to another
function.
     let button = GButton.button ~packing:(vbox#pack ~from:`END) ()
packing has type (widget -> unit) but vbox#pack has type
  ?from:Gtk.Tags.pack_type -> ?expand:bool ->
  ?fill:bool -> ?padding:int -> widget -> unit
meaning that some optional parameters are left after the partial
application. Currently the compiler discards them, by eta-expanding
the argument. But even this can subtly break the semantics in classic
mode (not in a fundamental way, but this is a petty headache).

Jacques Garrigue
---------------------------------------------------------------------------
Jacques Garrigue      Kyoto University     garrigue at kurims.kyoto-u.ac.jp
		<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>



      reply	other threads:[~2001-02-06 16:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-02-03 21:54 Mattias Waldau
2001-02-04 23:09 ` Maxence
2001-02-05  3:05 ` Jacques Garrigue
2001-02-05 18:18   ` Mattias Waldau
2001-02-06  1:58     ` Jacques Garrigue [this message]

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=20010206105806K.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=mattias.waldau@abc.se \
    --cc=max@sbuilders.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).