From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Malcolm Matalka <mmatalka@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Type variables and polymorphic variants
Date: Wed, 13 Mar 2013 11:06:54 +0900 [thread overview]
Message-ID: <F59E2AAD-B928-441A-A2A6-BA2E6ECB32AC@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <87ip4wffhd.fsf@li195-236.members.linode.com>
On 2013/03/13, at 6:57, Malcolm Matalka <mmatalka@gmail.com> wrote:
> Hello! I use polymorphic variants extensively in my code for getting
> the compiler to make sure I handle errors. However, I'm trying to write
> the following function which is proving hard, the errors are below.
>
> I have come across similar issues before and it is related to the type
> variable. I believe the problem is the [> in error because it can't know
> if I return a polymorphic variant in this function if that is the error
> or not.
>
> What is the cleanest way to write this function?
>
> val with_conn :
> host:string ->
> port:int ->
> (unit -> ('a, [> error ]) Deferred.Result.t) ->
> ('a, [> error ]) Deferred.Result.t
>
>
> Error: The implementation conn.ml does not match the interface conn.cmi:
> Values do not match:
> val with_conn :
> host:string ->
> port:int ->
> (unit ->
> ('a, [> `Bad_conn ] as 'b) Core.Std._result
> Async_core.Deferred.t) ->
> ('a, 'b) Core.Std._result Async_core.Deferred.t
> is not included in
> val with_conn :
> host:string ->
> port:int ->
> (unit -> ('a, [> error ]) Async.Std.Deferred.Result.t) ->
> ('a, [> error ]) Async.Std.Deferred.Result.t
>
The hint is in the error message:
> (unit -> ('a, [> `Bad_conn ] as 'b) Core.Std._result Async_core.Deferred.t) ->
> ('a, 'b) Core.Std._result Async_core.Deferred.t
You must use an "as" to connect the types:
val with_conn :
host:string ->
port:int ->
(unit -> ('a, [> error ] as 'e) Deferred.Result.t) ->
('a, 'e) Deferred.Result.t
Jacques Garrigue
prev parent reply other threads:[~2013-03-13 2:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-12 21:57 Malcolm Matalka
2013-03-13 2:06 ` Jacques Garrigue [this message]
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=F59E2AAD-B928-441A-A2A6-BA2E6ECB32AC@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=mmatalka@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;
as well as URLs for NNTP newsgroup(s).