<?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/07/7347ef3d79f516ef8692babe85c8791a"
  from="Brian Hurt &lt;brian.hurt@q...&gt;"
  author="Brian Hurt"
  date="2003-07-22T20:11:01"
  subject="[Caml-list] Variant parameterized method?"
  prev="2003/07/2d76bfee0b5a11a7db9f49191f910099"
  next="2003/07/2ad4fe2fc6657cf9aca64ef6fda489ec"
  next-in-thread="2003/07/2ad4fe2fc6657cf9aca64ef6fda489ec"
  prev-thread="2003/07/f4f0c2155e99d8e24366c19287802309"
  next-thread="2003/07/29d3d4246f320c31566fbe65671742e3"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Variant parameterized method?">
<msg 
  url="2003/07/7347ef3d79f516ef8692babe85c8791a"
  from="Brian Hurt &lt;brian.hurt@q...&gt;"
  author="Brian Hurt"
  date="2003-07-22T20:11:01"
  subject="[Caml-list] Variant parameterized method?">
<msg 
  url="2003/07/2ad4fe2fc6657cf9aca64ef6fda489ec"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2003-07-22T22:06:49"
  subject="Re: [Caml-list] Variant parameterized method?">
<msg 
  url="2003/07/e85ce98c80b46bc247f9dbfe9e5f0e10"
  from="Brian Hurt &lt;brian.hurt@q...&gt;"
  author="Brian Hurt"
  date="2003-07-22T22:35:48"
  subject="Re: [Caml-list] Variant parameterized method?">
</msg>
</msg>
</msg>
</thread>

<contents>

What I want to do is write a class interface like:

class virtual ['a] foo :
object
	method virtual doit : 'a
	method map : 'b. ('a -&gt; 'b) -&gt; 'b foo
end

The map function returns a new foo (not necessarily a new member of 
whatever derived from foo class the function is actually being called on) 
parameterized on the variant type.  This would be implemented more or less 
like:

class ['a] mapped_foo f_init e_init =
object
	val f = f_init
	val e = e_init
	method doit = f (e#doit)
	method map g =
		let h x = g (f x) in
		mapped_foo g e
end

The first prototype, when I try to compile it, returns with:

File "foo.mli", line 2, characters 6-100:
The abbreviation foo is used with parameters 'a foo
wich are incompatible with constraints 'b foo

[sic on the wich- minor typo there]. It works just fine if I change map to 
return a 'b list, or 'b array, or 'b Stack.t- it seems to be just 'b foo 
that's a problem.  Am I missing something?  If not, what is the suggested 
way for doing this?  I need map as a member function- it needs to behave 
differently on different types, and as I don't have reflextion, I need it 
to be a member function.  I'd prefer to keep it as a class for taste 
reasons.

Help is appreciated.

Brian


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

