<?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="2002/07/c1897db7ead6b5e80f6785eec2a57004"
  from="Brian Smith &lt;brian-l-smith@u...&gt;"
  author="Brian Smith"
  date="2002-07-09T06:23:10"
  subject="Re: [Caml-list] Polymorphic methods (syntax)"
  prev="2002/07/f9f4a8f9991df7c7143419e673d0dbe1"
  next="2002/07/bac42ff1a3a54d9b29b049daf3cdfaca"
  prev-in-thread="2002/07/5a7ec0755664b20f2ebf374c1c84515e"
  prev-thread="2002/07/bc2a965ab496aafdf2907a6d9bf85822"
  next-thread="2002/07/8d12ac2d99463ad68064b36be9eba6e9"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Polymorphic methods (longest error message ever!)">
<msg 
  url="2002/07/0753c3188698d9ea0f77236a0e41c552"
  from="Brian Smith &lt;brian-l-smith@u...&gt;"
  author="Brian Smith"
  date="2002-07-08T01:25:16"
  subject="[Caml-list] Polymorphic methods (longest error message ever!)">
<msg 
  url="2002/07/769799bb920dee01c56f1972fd80a499"
  from="John Max Skaller &lt;skaller@o...&gt;"
  author="John Max Skaller"
  date="2002-07-08T02:08:15"
  subject="Re: [Caml-list] Polymorphic methods (longest error message ever!)">
</msg>
<msg 
  url="2002/07/5a7ec0755664b20f2ebf374c1c84515e"
  from="Jacques Garrigue &lt;garrigue@k...&gt;"
  author="Jacques Garrigue"
  date="2002-07-08T02:53:12"
  subject="Re: [Caml-list] Polymorphic methods (longest error message ever!)">
</msg>
<msg 
  url="2002/07/c1897db7ead6b5e80f6785eec2a57004"
  from="Brian Smith &lt;brian-l-smith@u...&gt;"
  author="Brian Smith"
  date="2002-07-09T06:23:10"
  subject="Re: [Caml-list] Polymorphic methods (syntax)">
</msg>
</msg>
</thread>

<contents>
My original problem has already been fixed in the latest CVS version by
Jacques. And, I found out that there is some documentation about 
polymorphic methods on the O'Labl website. But, now I have another 
question, this time about syntax.

Consider,

# class ['a] example = object
      method id x : 'a = x
    end;;

Now, let's say I want to move the type variable from the class to the
method. Intuitively, I expect that O'Caml could use this definition:

# class example = object
      method id x = x
    end;;
Some type variables are unbound in this type:
   class example : object method id : 'a -&gt; 'a end
The method id has type 'a -&gt; 'a where 'a is unbound

I would hope that O'Caml would infer that the type of the method x is
('a -&gt; 'a) for all 'a. But, I know that Jacques has already said that
type inference of this type is not practical and so type annotations are
needed (Although, O'Caml actually does infer the correct type in this 
situation, it just disallows it). With that in mind, my next inutition 
is to try:

      # class example = object
          method ['a] id x : 'a = x
        end;;

or equivalently:

      # class example = object
          method ['a] id (x : 'a) = x
        end;;

Notice, I took the type parameter from the polymorphic class and just
moved it down to the method. But, currently this doesn't work either. I
propose that, if practical, this syntax be made to work. The benefits
are (1) symmetry with the syntax used for polymorphic classes, and (2)
less verbosity. As a comparison, in the current syntax (CVS version of
O'Caml), the definition would be:

# class example = object
      method id : 'a. 'a -&gt; 'a = fun x -&gt; x
    end;;

What do you think?

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

