<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/11/73c0239c821940641f06baea46c10fdd"
  from="Tom Hirschowitz &lt;Tom.Hirschowitz@e...&gt;"
  author="Tom Hirschowitz"
  date="2003-11-26T09:33:30"
  subject="[Caml-list] sum types with objects"
  prev="2003/11/4a128889eaa8ec56c6743f2f44a7612e"
  next="2003/11/615473df5cbf28e2eb2ecd0c2052564a"
  next-in-thread="2003/11/2555e37f48d9f56d1da0315e0ff9aee0"
  prev-thread="2003/11/abed68f2aff7b7909b4122601db58bdd"
  next-thread="2003/11/bdc1a5a58c194efb90903c9adcd7b097"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] sum types with objects">
<msg 
  url="2003/11/73c0239c821940641f06baea46c10fdd"
  from="Tom Hirschowitz &lt;Tom.Hirschowitz@e...&gt;"
  author="Tom Hirschowitz"
  date="2003-11-26T09:33:30"
  subject="[Caml-list] sum types with objects">
<msg 
  url="2003/11/2555e37f48d9f56d1da0315e0ff9aee0"
  from="Didier Remy &lt;remy@m...&gt;"
  author="Didier Remy"
  date="2003-11-26T13:32:41"
  subject="Re: [Caml-list] sum types with objects">
</msg>
</msg>
</thread>

<contents>

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 -&gt; 'b) -&gt; 'b list
  end
    ;;
class type ['a] list =
  object
    method hd : 'a
    method is_nil : bool
    method map : ('a -&gt; 'a) -&gt; 'a list
    method tl : 'a list
  end

The method map has type ('a -&gt; 'a) -&gt; '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

</contents>

</message>

