From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: "Christoph Höger" <christoph.hoeger@tu-berlin.de>
Cc: OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] Constraint Inference of a poly-type variable in a class-method
Date: Tue, 1 Dec 2015 18:42:30 +0900 [thread overview]
Message-ID: <CA6F8E2F-B2DF-4B60-B8F4-54A10B1F57A2@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <565D690A.7000005@tu-berlin.de>
On 2015/12/01 18:31, Christoph Höger wrote:
>
> Dear all,
>
> As a way to work-around my latest scalability issues, I want to attach a
> polymorphic method to a class with this functionality:
>
> let f t = t#s
> val f : < s : 'a; .. > -> 'a
>
> I know I can write:
>
> object method f = f end ;;
>
> and
>
> class x = object method f : 'a 'b . (<s : 'a; ..> as 'b) -> 'a = f end ;;
>
> However, the constraint might be somewhat larger, so I want it to be
> inferred. Is there a way to have the compiler infer a constraint on a
> poly-type variable?
No.
Basically, polymorphic method types cannot be compared, i.e. one type is not more general than another, so you always have to be explicit.
This said, if your problem is that you might be calling more methods of t, you can define a class type:
class type [‘a] t = object method s : ‘a end
Then you can write
method f : ‘a ‘b. (‘a #t as ‘b) -> ‘a = f
Jacques Garrigue
prev parent reply other threads:[~2015-12-01 9:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-01 9:31 Christoph Höger
2015-12-01 9:42 ` 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=CA6F8E2F-B2DF-4B60-B8F4-54A10B1F57A2@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=christoph.hoeger@tu-berlin.de \
/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