caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
To: caml-list@inria.fr
Subject: Re: [Caml-list] signature and 'a generic types
Date: Mon, 20 Jun 2005 18:19:41 +0200	[thread overview]
Message-ID: <871x6xvw4i.fsf@qrnik.zagroda> (raw)
In-Reply-To: <C6B8033B-6F2E-490D-85BB-55B37407448E@m4x.org> (Damien Bobillot's message of "Mon, 20 Jun 2005 17:20:40 +0200")

Damien Bobillot <damien.bobillot@m4x.org> writes:

>      module Module : (sig val func : 'a -> 'b end) =
>      struct let func a = a end
>
> Here Module.func's type is 'a -> 'a. According to me 'a -> 'a is a
> subtype of 'a -> 'b, it's 'a -> 'b with 'a = 'b.

It's not a subtype because 'a -> 'b really means
   forall 'a 'b. 'a -> 'b
and not
   exists 'a 'b. 'a -> 'b

If identity function had type forall 'a 'b. 'a -> 'b, I could use it
to transform an integer to a string.

>      module Module : (sig val func : 'a -> 'a end) = struct
>          let l = ref []
>          let func a = List.assoc a !l

Here the type of func is
   '_a -> '_b
which means something like
   exists 'a 'b. 'a -> 'b
For details Google for "value polymorphism" or "imperative polymorphism".
(Why this is not explained in OCaml manual?)

This is not a subtype of forall 'a. 'a -> 'a.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


  parent reply	other threads:[~2005-06-20 16:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-20 15:20 Damien Bobillot
2005-06-20 15:59 ` [Caml-list] " Virgile Prevosto
2005-06-20 16:06 ` Stephane Glondu
2005-06-20 16:19 ` Marcin 'Qrczak' Kowalczyk [this message]
2005-06-20 22:31 ` Michael Alexander Hamburg

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=871x6xvw4i.fsf@qrnik.zagroda \
    --to=qrczak@knm.org.pl \
    --cc=caml-list@inria.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).