From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p8RFQam9023042 for ; Tue, 27 Sep 2011 17:26:40 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am0BAOTqgU5KfVI0imdsb2JhbABBp3QIFAEBAQoJDQcSBiKBUwEBAQMBEgITGQEbHQEDAQsGBQQHOyMRAQUBHAY1h1YCnTcKi0yCXIUVO4huAgQGhiVgBJNShSKBKoY+PYNv X-IronPort-AV: E=Sophos;i="4.68,449,1312149600"; d="scan'208,217";a="110784508" Received: from mail-ww0-f52.google.com ([74.125.82.52]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 27 Sep 2011 17:26:40 +0200 Received: by wwj40 with SMTP id 40so8222641wwj.9 for ; Tue, 27 Sep 2011 08:26:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=cc:message-id:from:to:in-reply-to:content-type:mime-version:subject :date:references:x-mailer; bh=YF1E3NMEDv8NM1KLbMy5IOH5qC4diN7ADDh+LTY3qKQ=; b=SaL9eOA5fAjl0LAwBWCu6F9MP8tdoLflLThTPXl1j3mn5ZVjEUIeaDHUvS/fXejP4B fO5uy6hY2UEjXNqIy/oJ405Esd+BFqx+k9sM7uDAqWus1V2l7zH1o/b/Z7XRF1fBJJ4B 3GA1ujaCT6Ki3Q0Wl1tDo9Y/yhlMiDUaTuRVg= Received: by 10.216.221.42 with SMTP id q42mr9374387wep.16.1317137199612; Tue, 27 Sep 2011 08:26:39 -0700 (PDT) Received: from [192.168.0.10] (lau06-5-88-176-33-221.fbx.proxad.net. [88.176.33.221]) by mx.google.com with ESMTPS id f26sm36234885wbp.7.2011.09.27.08.26.37 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 27 Sep 2011 08:26:38 -0700 (PDT) Cc: OCaML Mailing List Message-Id: <53C8B18E-A3AD-4DB1-A477-EE7FA7846845@gmail.com> From: Christophe Papazian To: Walter Cazzola In-Reply-To: Content-Type: multipart/alternative; boundary=Apple-Mail-1--472419616 Mime-Version: 1.0 (Apple Message framework v936) Date: Tue, 27 Sep 2011 17:26:36 +0200 References: X-Mailer: Apple Mail (2.936) Subject: Re: [Caml-list] still silly issues on polymorphic types --Apple-Mail-1--472419616 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit > > uhm, I have a couple of questions I don't understand on your > explanation: > - why the most general type is int->'a and not 'a -> 'b? Because if I need a function of type int -> 'a I can give a function of type 'a -> 'b. But if I need a function of type 'a -> 'b I can not use a function of type int -> 'a. So int -> 'a is more general and 'a -> 'b is more specific. General rule : if a < b then (a->c) > (b->c) > - does this mean that I can't have a general type that could be > matched > by 'a -> 'a list -> 'a list and int -> int -> int ? > if you want to get a supertype of a -> b and c -> d you need to find a subtype of a and c AND find a supertype of b and d. So for example for ('a -> ( 'a list -> 'a list)) and (int -> (int -> int)) you need - a subtype of 'a and int : it's int. you have one. - a supertype of ('a list -> 'a list) and (int -> int) (reapply the same procedure) -a subtype of 'a list and int : there is no such thing in ocaml, so there is no supertype. So to answer your question, you can't. But as Jacques Garrigue said, you don't need either, and you can use abstract type and "with type" construction. > Walter > > -- --Apple-Mail-1--472419616 Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable

uhm, I have = a couple of questions I don't understand on your
explanation:
- why = the most general type is int->'a and not 'a -> 'b?

Because if I need a function of type int -> 'a I= can give a function of type 'a -> 'b.
But if I need a functio= n of type 'a -> 'b I can not use a function of type int -> 'a.
<= div>So int -> 'a is more general and 'a -> 'b is more specific.=

General rule : if a < b then (a->c) > (b->c= ) 

- does this mean that I ca= n't have a general type that could be matched
  by 'a -> '= a list -> 'a list  and int -> int -> int ?


if you want to get a supertype of a -> b and= c -> d you need to
find a subtype of a and c AND find a super= type of b and d.

So for example for ('a -> ( 'a= list -> 'a list)) and (int -> (int -> int))
you need
 - a subtype of 'a and int : it's int. you have one.
 - a supertype of ('a list -> 'a list) and (int -> int) (reappl= y the same procedure)
      -a subtype of 'a list = and int : there is no such thing in ocaml, so there is no supertype.
<= div>
So to answer your question, you can't. But as Jacques Ga= rrigue said, you don't need either,
and you can use abstract type= and "with type" construction.



=

Walter

--

= --Apple-Mail-1--472419616--