Hello.

>> Error: This type scheme cannot quantify 'b :
>> it escapes this scope.

> The answer is unfortunately short: there is no solution.

  Thank you for the definitive and quick answer!

> Namely recursive types in ocaml must be regular.
> I.e., they must expand to a finite graph.
> In particular this means that, inside the class lst, all occurences
> of lst must have exactly the parameter 'a.

  Just interesting: where this graph and its finiteness property
are used?

> As you have already found, you can avoid this problem by
> defining a record which "hides" the use of lst.
> Namely, you must break the cycle with a datatype,
> either record or sum type.
> Unfortunately this also means that this type has to belong
> to some module, and you also lose subtyping.

  I've tried to make the type (lst 'b) belong to some first-class
module returned by some method call (to object with type
lst 'a), but without any success.
  And while playing with first-class modules I've noted that
I can't constrain the parametric type of module:
let module M = (lst#mapmodule : Mappable with type t 'a = list a)
 -- one more way is blocked (but don't know was it the way
really).


  But I can reformulate (and maybe make easier) my task:
I can move the code that work with different type parameters
(lst 'a -> lst 'b) to simple functions.  For example, "map" for
containers -- to the function like "container_map", which
will work with containers (objects that have some methods),
to make the code work:
container_map func (new lst [1;2;3]);
container_map func (new arr [|1;2;3|]).
  I understand that the imaginable "container_map" function
should require some method with some type, that can
give me the value of type lst 'b for lst 'a in case of lists,
and the value of type arr 'b for arr 'a in case of arrays,
but I can't write such type (even with first-class modules).
  Is it impossible too?

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to