From: Brian Rogoff <bpr@artisan.com>
To: Narayanan.Krishnamurthy@motorola.com
Cc: caml-list@inria.fr, nari@ibmoto.com
Subject: Re: [Caml-list] Polymorphic methods in class objects
Date: Tue, 20 Aug 2002 14:56:45 -0700 [thread overview]
Message-ID: <15714.47901.651153.447296@granite.artisan.com> (raw)
In-Reply-To: <3D62A9DE.7C2B2CFA@motorola.com>
Narayanan Krishnamurthy writes:
> (*********************************************)
> class polym =
> object(self)
> val i = 0
> method private func1 j = j + 1
> method private func2 j = string_of_int j
> method private func3 j = float_of_int j
> method private foo polymf n =
> polymf n
> method goo () =
> self#foo self#func1 2
> method hoo () =
> self#foo self#func2 2
> method boo () =
> self#foo self#func3 2
> end
You need a bit of explicit typing. See Section 3.10 of the manual for
OCaml 3.06.
# class polym =
object(self)
val i = 0
method private func1 j = j + 1
method private func2 j = string_of_int j
method private func3 j = float_of_int j
method private foo : 'a . (int -> 'a) -> int -> 'a =
fun polymf n -> polymf n
method goo () =
self#foo self#func1 2
method hoo () =
self#foo self#func2 2
method boo () =
self#foo self#func3 2
end;;
class polym :
object
val i : int
method boo : unit -> float
method private foo : (int -> 'a) -> int -> 'a
method private func1 : int -> int
method private func2 : int -> string
method private func3 : int -> float
method goo : unit -> int
method hoo : unit -> string
end
# let m = new polym;;
val m : polym = <obj>
# m#goo ();;
- : int = 3
# m#hoo ();;
- : string = "2"
# m#boo ();;
- : float = 2.
-- 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
prev parent reply other threads:[~2002-08-20 21:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-20 20:43 Narayanan Krishnamurthy
2002-08-20 20:46 ` [Caml-list] " Narayanan Krishnamurthy
2002-08-20 21:56 ` Brian Rogoff [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=15714.47901.651153.447296@granite.artisan.com \
--to=bpr@artisan.com \
--cc=Narayanan.Krishnamurthy@motorola.com \
--cc=caml-list@inria.fr \
--cc=nari@ibmoto.com \
/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