Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Brian Smith <brian-l-smith@uiowa.edu>
To: OCaml Mailing list <caml-list@inria.fr>
Subject: Re: [Caml-list] Polymorphic methods (syntax)
Date: Tue, 09 Jul 2002 01:23:06 -0500	[thread overview]
Message-ID: <3D2A814A.5020303@uiowa.edu> (raw)
In-Reply-To: <3D28E9F8.5020308@uiowa.edu>

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


      parent reply	other threads:[~2002-07-09  6:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-08  1:25 [Caml-list] Polymorphic methods (longest error message ever!) Brian Smith
2002-07-08  2:08 ` John Max Skaller
2002-07-08  2:53 ` Jacques Garrigue
2002-07-09  6:23 ` Brian Smith [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3D2A814A.5020303@uiowa.edu \
    --to=brian-l-smith@uiowa.edu \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox