Version française
Home     About     Download     Resources     Contact us    
Browse thread
grammar for class types, reraised
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Prevost <prevost@z...>
Subject: Re: grammar for class types, reraised
Jerome Vouillon <Jerome.Vouillon@inria.fr> writes:

> This would probably be possible, but it is not trivial. And then, you
> would probably expect to be able to include in the recursion other
> construct, such as value definitions (for instance, if a function
> using the type b is used by the class a). This would make the
> implementation even more complicated.
> 
> On the other hand, you can get rid of the mutual recursion by adding a
> type parameter to one of the type. For instance, you can change
>     class type a = object method m : b end
>     and
>     type b = Node of a | Tree of b * b
> into
>     type 'a b = Node of 'a | Tree of b * b
>     class type a = object method m : a b end

My situation was somewhat more obscene, and would've required this:

type ('foo,'bar,'baz,'qux,'blatz,'zuttle,'potz,...) cast =
 | Foo of 'foo
 | Bar of 'bar
 | ...

class type node = object method downcast : (foo,bar,...) cast end
and bar = object ... end
...

The whole point of the excercise was to have a downcast method for a
set of specific classes, in a type-safe way.  I eventually wrote code
using < ... > for all of the types.

John.