Browse thread
Polymorphic method question
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2006-07-10 (19:21) |
From: | brogoff <brogoff@s...> |
Subject: | Polymorphic method question |
Hi, I'm sure I'll slap my forehead in disgust when someone lifts the scales from my eyes, but I'm once again perplexed by a type error from OCaml when using objects. Can someone tell me why I get the error from the second case (with the classes connected by "and") when the first case is OK? BTW, This example was distilled from one in which I could not cleanly remove the class recursion, one involving an "extensible visitor" in which there is a recursion between the visited and visitor classes. Assuming there's an obvious answer to my first question, is there a nice workaround in this case? brogoff@denali[tricks]$ ocaml Objective Caml version 3.09.2 # class virtual ['a] bar = object method virtual get : 'a end;; class virtual ['a] bar : object method virtual get : 'a end # class virtual foobar = object method virtual f : 'a . 'a bar -> 'a end;; class virtual foobar : object method virtual f : 'a bar -> 'a end # class virtual ['a] bar = object method virtual get : 'a end and foobar = object method virtual f : 'a . 'a bar -> 'a end;; Characters 115-132: method virtual f : 'a . 'a bar -> 'a ^^^^^^^^^^^^^^^^^ This type scheme cannot quantify 'a : it escapes this scope. -- -- Brian