* [Caml-list] Constraint Inference of a poly-type variable in a class-method
@ 2015-12-01 9:31 Christoph Höger
2015-12-01 9:42 ` Jacques Garrigue
0 siblings, 1 reply; 2+ messages in thread
From: Christoph Höger @ 2015-12-01 9:31 UTC (permalink / raw)
To: caml users
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?
regards,
Christoph
--
Christoph Höger
Technische Universität Berlin
Fakultät IV - Elektrotechnik und Informatik
Übersetzerbau und Programmiersprachen
Sekr. TEL12-2, Ernst-Reuter-Platz 7, 10587 Berlin
Tel.: +49 (30) 314-24890
E-Mail: christoph.hoeger@tu-berlin.de
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Constraint Inference of a poly-type variable in a class-method
2015-12-01 9:31 [Caml-list] Constraint Inference of a poly-type variable in a class-method Christoph Höger
@ 2015-12-01 9:42 ` Jacques Garrigue
0 siblings, 0 replies; 2+ messages in thread
From: Jacques Garrigue @ 2015-12-01 9:42 UTC (permalink / raw)
To: Christoph Höger; +Cc: OCaML List Mailing
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-12-01 9:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-01 9:31 [Caml-list] Constraint Inference of a poly-type variable in a class-method Christoph Höger
2015-12-01 9:42 ` Jacques Garrigue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox