From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Joel Reymont <joelr1@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] fighting the type system
Date: Thu, 24 Mar 2011 08:56:32 +0900 [thread overview]
Message-ID: <622E23E3-5614-4ADE-B517-672577A406A2@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <07EE3576-E5F0-4187-AE8C-DEFEA5C92303@gmail.com>
On 2011/03/24, at 7:01, Joel Reymont wrote:
> How do I do this?
>
> Thanks in advance, Joel
Well, you don't because this is clearly unsound.
> --- Util.ml
>
> type 'a writable = < write : Protocol.t -> unit; .. > as 'a
>
> module type Endpoint =
> sig
> val request : unit -> 'a writable
> val response : 'a writable -> 'b writable
> val read_request : Protocol.t -> 'a writable
> val read_response : Protocol.t -> 'a writable
> end
Your definition of 'a writable is actually equivalent to writing
class type writable = object method write : Protocol.t -> unit end
and replacing uses of 'a writable by #writable.
The trouble is that returning a value of type #writable is unsound,
since it means that this value has any possible method, including write.
So you would be able to write:
(request ())#foo
and have the type checker happily comply.
I'm not sure of what you're trying to do.
If you just want the Endpoint interface to specify an object type
containing at least write, you could use a private row type:
module type Endpoint =
sig
type writable = private <write : Protocol.t -> unit; .. >
val request : unit -> writable
val response : writable -> writable
val read_request : Protocol.t -> writable
val read_response : Protocol.t -> writable
end
You can then instantiate it with a concrete type, using
Endpoint with type writable := mywriter
Jacques Garrigue
next prev parent reply other threads:[~2011-03-23 23:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-23 22:01 Joel Reymont
2011-03-23 22:19 ` [Caml-list] " Joel Reymont
2011-03-23 23:52 ` Joel Reymont
2011-03-23 23:56 ` Jacques Garrigue [this message]
2011-03-24 0:16 ` [Caml-list] " Joel Reymont
2011-03-24 0:48 ` Jacques Garrigue
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=622E23E3-5614-4ADE-B517-672577A406A2@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=joelr1@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