caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Stephane Glondu <steph@glondu.net>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] signature and 'a generic types
Date: Mon, 20 Jun 2005 09:06:03 -0700	[thread overview]
Message-ID: <200506200906.03718.steph@glondu.net> (raw)
In-Reply-To: <C6B8033B-6F2E-490D-85BB-55B37407448E@m4x.org>

On Monday 20 June 2005 08:20, Damien Bobillot wrote:
> Hello,
>
> Look at the following code :
>
>      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 is not relevant. To write this, every 'a -> 'a object must be seeable as a 
'a -> 'b object, which is obviously wrong (otherwise, e.g. func 0 would have 
any type).

> I also try to use the reverse match :
>
>      module Module : (sig val func : 'a -> 'a end) = struct
>          let l = ref []
>          let func a = List.assoc a !l
>      end
>
> Where Module.func is of type 'a -> 'b. Ocamlc also give me an error,
> but I completely understand it here : 'a -> 'b is really not a
> subtype of 'a -> 'a.

Again, the explanation is not relevant. Here, func is not of type 'a -> 'b, 
but '_a -> '_b instead, that means that the first usage of func will freeze 
the type (you won't be able to use func 4, then func true). It happens every 
time you use references. Otherwise, you could write e.g. l := [(1,1)]; func 
true.

> In this case I also don't understand why neither " 'a -> 'b is
> included in 'a -> 'a " nor " 'a -> 'a is included in 'a -> 'b " are
> true. To my mind, one should be true.

'a -> 'b is included in 'a -> 'a, but not the contrary (intuitively, functions 
of the first type don't terminate properly, e.g. let f a = raise Exit).


Stephane Glondu.


  parent reply	other threads:[~2005-06-20 16:06 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 [this message]
2005-06-20 16:19 ` Marcin 'Qrczak' Kowalczyk
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=200506200906.03718.steph@glondu.net \
    --to=steph@glondu.net \
    --cc=caml-list@yquem.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).