caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Polymorphic method problem
@ 2004-07-06 18:23 Christian Szegedy
  2004-07-06 21:38 ` Alex Baretta
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Christian Szegedy @ 2004-07-06 18:23 UTC (permalink / raw)
  To: caml-list

Can anyone tell me, why does the following piece of
code fail to compile, and how can I achieve
equivalent effect in the most convenient way?

class a () =
   object(self)
      method f : 'a. ((< f : unit; .. > as 'a) -> unit) = fun other -> 
other#f 
      method g = (self :> a)
   end

Thanks in advance!


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Polymorphic method problem
  2004-07-06 18:23 [Caml-list] Polymorphic method problem Christian Szegedy
@ 2004-07-06 21:38 ` Alex Baretta
  2004-07-06 22:00   ` Christian Szegedy
  2004-07-06 23:44 ` Olivier Andrieu
  2004-07-07  1:53 ` Jacques GARRIGUE
  2 siblings, 1 reply; 8+ messages in thread
From: Alex Baretta @ 2004-07-06 21:38 UTC (permalink / raw)
  To: Christian Szegedy; +Cc: caml-list

Christian Szegedy wrote:
> Can anyone tell me, why does the following piece of
> code fail to compile, and how can I achieve
> equivalent effect in the most convenient way?
> 
> class a () =
>   object(self)
>      method f : 'a. ((< f : unit; .. > as 'a) -> unit) = fun other -> 
> other#f      method g = (self :> a)
>   end
> 
> Thanks in advance!
> 

Your type annotations are not correct. Omit the ones which are not 
strictly needed.

class a =
object (self)
   method f : 'a.((<f:unit; ..> as 'a) -> unit) > as 'a) -> unit) =
     fun x -> x # f
   method g = self
end

Alex

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Polymorphic method problem
  2004-07-06 21:38 ` Alex Baretta
@ 2004-07-06 22:00   ` Christian Szegedy
  2004-07-06 23:16     ` William Lovas
  0 siblings, 1 reply; 8+ messages in thread
From: Christian Szegedy @ 2004-07-06 22:00 UTC (permalink / raw)
  To: caml-list

Dear Alex!

I tried to run your code, but it has obvious syntax errors.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Polymorphic method problem
  2004-07-06 22:00   ` Christian Szegedy
@ 2004-07-06 23:16     ` William Lovas
  2004-07-06 23:53       ` Alex Baretta
  0 siblings, 1 reply; 8+ messages in thread
From: William Lovas @ 2004-07-06 23:16 UTC (permalink / raw)
  To: caml-list

On Wed, Jul 07, 2004 at 12:00:04AM +0200, Christian Szegedy wrote:
> Dear Alex!
> 
> I tried to run your code, but it has obvious syntax errors.

I suspect a copy/paste error.  Here's the corrected code:

    class a =
    object (self)
      method f : 'a.((<f:unit; ..> as 'a) -> unit) =
          fun x -> x # f
      method g = self
    end

Hope this helps.

cheers,
William

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Polymorphic method problem
  2004-07-06 18:23 [Caml-list] Polymorphic method problem Christian Szegedy
  2004-07-06 21:38 ` Alex Baretta
@ 2004-07-06 23:44 ` Olivier Andrieu
  2004-07-07  1:53 ` Jacques GARRIGUE
  2 siblings, 0 replies; 8+ messages in thread
From: Olivier Andrieu @ 2004-07-06 23:44 UTC (permalink / raw)
  To: szegedy; +Cc: caml-list

 Christian Szegedy [Tue, 06 Jul 2004]:
 > Can anyone tell me, why does the following piece of
 > code fail to compile, and how can I achieve
 > equivalent effect in the most convenient way?
 >
 > class a () =
 >    object(self)
 >       method f : 'a. ((< f : unit; .. > as 'a) -> unit) = fun other -> 
 > other#f 
 >       method g = (self :> a)
 >    end

Defining a class type beforehand helps:

,----
| # class type a_t = object method f : < f : unit; ..> -> unit method g : a_t end ;;
| class type a_t =
|   object method f : < f : unit; .. > -> unit method g : a_t end
| 
| # class a () : a_t = object (self) 
|     method f : 'a. ((< f : unit; .. > as 'a) -> unit) = fun other ->
|   other#f 
|     method g = (self :> a_t) 
|   end ;;
| class a : unit -> a_t
`----

-- 
   Olivier

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Polymorphic method problem
  2004-07-06 23:16     ` William Lovas
@ 2004-07-06 23:53       ` Alex Baretta
  0 siblings, 0 replies; 8+ messages in thread
From: Alex Baretta @ 2004-07-06 23:53 UTC (permalink / raw)
  To: William Lovas; +Cc: caml-list

William Lovas wrote:
> On Wed, Jul 07, 2004 at 12:00:04AM +0200, Christian Szegedy wrote:
> 
>>Dear Alex!
>>
>>I tried to run your code, but it has obvious syntax errors.

Indeed! DdR's ledit is a very nice tool to quickly type code into the 
interpreter, but it has the obvious disadvantage of not allowing easy 
copying out of the line buffer.

Sorry for the mistake, and thanks to William for the correction.

> 
> I suspect a copy/paste error.  Here's the corrected code:
> 
>     class a =
>     object (self)
>       method f : 'a.((<f:unit; ..> as 'a) -> unit) =
>           fun x -> x # f
>       method g = self
>     end
> 


Alex

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Polymorphic method problem
  2004-07-06 18:23 [Caml-list] Polymorphic method problem Christian Szegedy
  2004-07-06 21:38 ` Alex Baretta
  2004-07-06 23:44 ` Olivier Andrieu
@ 2004-07-07  1:53 ` Jacques GARRIGUE
  2004-07-08 22:51   ` Christian Szegedy
  2 siblings, 1 reply; 8+ messages in thread
From: Jacques GARRIGUE @ 2004-07-07  1:53 UTC (permalink / raw)
  To: szegedy; +Cc: caml-list

From: szegedy@t-online.de (Christian Szegedy)

> Can anyone tell me, why does the following piece of
> code fail to compile, and how can I achieve
> equivalent effect in the most convenient way?
> 
> class a () =
>    object(self)
>       method f : 'a. ((< f : unit; .. > as 'a) -> unit) = fun other -> 
> other#f 
>       method g = (self :> a)
>    end

There was a bug in the subtyping algorithm.
Hopefully, it's now fixed in CVS.

A workaround at the source level is to define your type in advance:

class type ta = object
  method f : <f : unit; ..> -> unit
  method g : ta
end
class a () =
  object(self : #ta)
    method f other = other#f
    method g = (self :> ta)   
  end

Jacques Garrigue

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Caml-list] Polymorphic method problem
  2004-07-07  1:53 ` Jacques GARRIGUE
@ 2004-07-08 22:51   ` Christian Szegedy
  0 siblings, 0 replies; 8+ messages in thread
From: Christian Szegedy @ 2004-07-08 22:51 UTC (permalink / raw)
  Cc: caml-list

> There was a bug in the subtyping algorithm.
> Hopefully, it's now fixed in CVS.

Thanks for your fast reaction!


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-07-08 22:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-06 18:23 [Caml-list] Polymorphic method problem Christian Szegedy
2004-07-06 21:38 ` Alex Baretta
2004-07-06 22:00   ` Christian Szegedy
2004-07-06 23:16     ` William Lovas
2004-07-06 23:53       ` Alex Baretta
2004-07-06 23:44 ` Olivier Andrieu
2004-07-07  1:53 ` Jacques GARRIGUE
2004-07-08 22:51   ` Christian Szegedy

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).