Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] subtyping, polymorphism, higher order types.....
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Fernando Alegre <fernando@c...>
Subject: Re: [Caml-list] subtyping, polymorphism, higher order types.....
On Sat, Jul 05, 2003 at 11:21:26AM +0900, Jacques Garrigue wrote:

> This looks very much like an ocaml object type to me...
> Is the absence of labels for fields important?
> 
> Note that you can also encode the above with polymorphism:
> 
>   type 'a point = int * int * 'a
>   type 'a color_point = (int * 'a) point
> 
> The only trouble here is that there is no way to create heterogeneous
> collections, since you cannot coerce a [unit color_point] to a [unit
> point]. Actually, this just comes from a missing relation in the ocaml
> type algebra: the type Obj.t is not recognized as a supertype for all
> types. If this were the case then you would be able to write:
>   let l = [ (p :> Obj.t point); (cp :> Obj.t point) ]
> 
> That would be easy enough to add, but is it that useful?

I think yes. That would allow us to avoid creating ad-hoc classes whose only
use is such heterogeneous storage. This would save quite a few lines of
wrapping code when the basic data structure is a record or a sum type that
is extended with a problem-specific type.

Currently, the problem is not just heterogeneous collections. In our program,
a mutable variable of type 'a model can not be reused to solve one model
after another without exiting the program and restarting with a different
model, unless we wrap everything in classes. Exiting the program is really
inconvenient for interactive user interfaces, and wrapping the code adds
many unnecessary lines. So, something like Obj.t coercion would be really
useful. 

Fernando

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