caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] sum types with objects
@ 2003-11-26 18:42 Tom Hirschowitz
  2003-11-26 13:37 ` Didier Remy
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Hirschowitz @ 2003-11-26 18:42 UTC (permalink / raw)
  To: caml-list


Hi all,

when trying to implement lists with objects and classes, I run into
the following issue.

The idea is to define a class type list, parameterized over the type
'a of elements, and containing the methods is_nil, hd, tl, map. Then,
I planned to define two classes nil and cons for building objects of
type list.

The problem arises during the typing of list:

# class type ['a] list = object
  method is_nil : bool
    method hd : 'a
    method tl : 'a list
    method map : ('a -> 'b) -> 'b list
  end
    ;;
class type ['a] list =
  object
    method hd : 'a
    method is_nil : bool
    method map : ('a -> 'a) -> 'a list
    method tl : 'a list
  end

The method map has type ('a -> 'a) -> 'a list, which is not what I
want.  Trying to explicitely quantify 'b is also wrong, because 'b
escapes its scope.

Does someone know how to make this work?

-------------------
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] 2+ messages in thread

end of thread, other threads:[~2003-11-26 13:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-26 18:42 [Caml-list] sum types with objects Tom Hirschowitz
2003-11-26 13:37 ` Didier Remy

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