Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: jonathan.roewen@gmail.com
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Mixing variant types...
Date: Thu, 12 Jan 2006 12:22:30 +0900 (JST)	[thread overview]
Message-ID: <20060112.122230.45186948.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <ad8cfe7e0601111724t44b6966di5d803949161676ee@mail.gmail.com>

From: Jonathan Roewen <jonathan.roewen@gmail.com>

> File "window_system.ml", line 99, characters 23-50:
> This expression cannot be coerced to type
>   ws_event = (window * [ `New_window | `Repaint ]) Event.event;
> it has type (window * event) Event.event but is here used with type
>   ws_event = (window * [ `New_window | `Repaint ]) Event.event
> Type event = [ `Repaint ] is not compatible with type
>   [ `New_window | `Repaint ]
> The first variant type does not allow tag(s) `New_window
> 
> The toplevel has just proven to me that this can be done, so I don't
> understand what's going on here.

The reason is simple: Event.event is not marked ascovariant in its
parameter. So even if t1 is a subtype of t2, this does not imply that
t1 Event.event will be a subtype of t2 Event.event.
After thinking a bit of the semantics, it seems that it would be safe
to make Event.event covariant. Of course Event.channel cannot be
made covariant, as it can be used both to send and receive values.

You can already simulate subtyping using Event.wrap:
  Event.wrap e (fun x -> (x : t1 :> t2))
will turn a t1 event into a t2 event.
(So this probably means that Event.event should be covariant to start
with...)

For practical applications, the solution suggested by skaller might be
satisfactory too.

Jacques


  parent reply	other threads:[~2006-01-12  3:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-11 10:36 Jonathan Roewen
2006-01-12  1:24 ` Jonathan Roewen
2006-01-12  2:45   ` skaller
2006-01-12  3:22   ` Jacques Garrigue [this message]
2006-01-12  3:57     ` skaller
2006-01-13  4:57       ` Jacques Garrigue
2006-01-13  7:56         ` skaller
2006-01-13  9:37           ` Jacques Garrigue
2006-01-12  3:59     ` Jonathan Roewen
  -- strict thread matches above, loose matches on Subject: below --
2006-01-11  9:56 Jonathan Roewen

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=20060112.122230.45186948.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@yquem.inria.fr \
    --cc=jonathan.roewen@gmail.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