Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Polymorphic methods (longest error message ever!)
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brian Smith <brian-l-smith@u...>
Subject: Re: [Caml-list] Polymorphic methods (syntax)
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 -> 'a end
The method id has type 'a -> 'a where 'a is unbound

I would hope that O'Caml would infer that the type of the method x is
('a -> '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 -> 'a = fun x -> 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