caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
To: Olivier Andrieu <oandrieu@nerim.net>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Yet another question about insufficient polymorphism
Date: Wed, 12 Mar 2008 22:13:35 +0000	[thread overview]
Message-ID: <20080312221335.GA16935@annexia.org> (raw)
In-Reply-To: <95513600803121457l17e90817y54d419784462ae85@mail.gmail.com>

[Hope you don't mind this but I've CC'd back to caml-list ...]

On Wed, Mar 12, 2008 at 10:57:46PM +0100, Olivier Andrieu wrote:
> On Wed, Mar 12, 2008 at 9:59 PM, Richard Jones <rich@annexia.org> wrote:
> > On Wed, Mar 12, 2008 at 09:19:32PM +0100, Olivier Andrieu wrote:
> >  > aren't you missing a variance annotation ? like :
> >  >
> >  > type -'a component
> >
> >  I don't know because no one has ever been able to explain covariance &
> >  contravariance to me in a comprehensible way !
> 
> there's this post where I tried to explain that to someone:
> http://groups.google.com/group/fa.caml/msg/584ea2139b69f0ed
> 
> >  I added the '-' but it doesn't appear to have fixed the problem
> >  unfortunately.
> 
> You'll need it anyway I think :)
> What's the type of your functions that create components ? (textbox
> and button ?)

val button : int -> int -> string -> [ `Button | `Component ] component

val textbox : int -> int -> int -> int -> flag list ->
    [ `Component | `Textbox ] component

> >  Someone mentioned that it might be because when I added the signature,
> >  the type became abstract (before, the implementation of the type was
> >  exposed).  I can't make that work either though, but maybe because my
> >  type is slightly different than it was before ...
> 
> You'll probably have to add some coercions , like:
> 
>   let as_co c = (c :> [`Component] component)
> 
> and then
> 
>   form_add_components form [as_co text; as_co b1; as_co b2];

Right, this is very confusing.  Adding the -'a annotation:

  type -'a component

and:

  let as_co c = (c :> [`Component] component) in
  form_add_components form [as_co text; as_co b1; as_co b2];              

works.

However omitting the minus in "type -'a ..." breaks it, and changing
the list to:

  ([text; b1; b2] :> [`Component] component list)

doesn't work either.

I guess I'll need to read about co-/contra-variance.

Rich.

-- 
Richard Jones
Red Hat


  parent reply	other threads:[~2008-03-12 22:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-12 19:34 Richard Jones
     [not found] ` <95513600803121319y508923a1vb36ac59c21e93f5b@mail.gmail.com>
     [not found]   ` <20080312205911.GA14545@annexia.org>
     [not found]     ` <95513600803121457l17e90817y54d419784462ae85@mail.gmail.com>
2008-03-12 22:13       ` Richard Jones [this message]
2008-03-12 22:56         ` [Caml-list] " Olivier Andrieu
2008-03-18 10:56 ` Richard Jones

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=20080312221335.GA16935@annexia.org \
    --to=rich@annexia.org \
    --cc=caml-list@inria.fr \
    --cc=oandrieu@nerim.net \
    /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).